arrays - TableView 与所有习语

标签 arrays swift tableview idioms

我有一个 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;

    }
}

这将为您提供选择多个行项目的选项,如下所示

Multiple Row Selection in table view

关于arrays - TableView 与所有习语,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35532525/

相关文章:

javascript - 展平数组对象的数组 JavaScript

javascript - 考虑 2 个不同的键,计算 JSON 数组中的唯一元素 - Javascript

swift - 访问多个类中的一个函数

在单独的文件中声明的 Swift 协议(protocol)

checkbox - TableView JavaFX 中的居中复选框

java - 将表保存到剪贴板 javaFx

jquery - 光滑的网格将分页中的所有行分组

python - 快速有效地减去数组的方法

swift - 将 UITableView 约束为 InputAccessory

ios - 使用未解析的标识符 ParseCrashReporting