带有所有习语的 TableView
TableView with all the Idioms
我有一个 tableView,我想向用户显示一个语言列表,用户可以 select 一种或多种语言。有没有办法让 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;
}
}
这将为您提供 select 多行项目的选项,如下所示
我有一个 tableView,我想向用户显示一个语言列表,用户可以 select 一种或多种语言。有没有办法让 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;
}
}
这将为您提供 select 多行项目的选项,如下所示