我有一个 tableView,我想向用户显示语言列表,并且用户可以选择一种或多种口语语言。有没有办法让 swift 显示它的列表?
最佳答案
在你的TableViewControlloer
let langues = ["Mandarin","Spanish","English","Hindi","Arabic","Portuguese","Bengali","Russian","Japanese","Punjabi"]
重写以下两个函数
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("reuseIdentifier", forIndexPath: indexPath)
cell.textLabel?.text = langues[indexPath.row]
return cell
}
和
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath){
let cell = tableView.cellForRowAtIndexPath(indexPath)
if (cell?.accessoryType == UITableViewCellAccessoryType.Checkmark){
cell!.accessoryType = UITableViewCellAccessoryType.None;
}else{
cell!.accessoryType = UITableViewCellAccessoryType.Checkmark;
}
}
这将为您提供选择多个行项目的选项,如下所示
关于arrays - TableView 与所有习语,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35532525/