ios - 如何在 Swift 中循环访问 UITableView 中的数据

标签 ios uitableview swift loops foreach

我正在使用 Alamofire 库进行 http 请求。

我知道如何在纯文本字段中循环:

for option in json["options"] {
    let opts = json["options"]["is_selected"].string

    if json["options"][ctr]["is_selected"] == 1 {
        if json["options"][ctr]["id"] == "8" {
            self.emailSwitch.on = true
            self.unameSwitch.on = true
         }
     }
     println(json["options"][ctr]["id"])
     ctr++
 }

但是如何在 TableView 中执行此操作?

最佳答案

您可以像这样迭代 uitableview:

for section in 0..<tableView.numberOfSections() {

    for row in 0..<tableView.numberOfRowsInSection(section) {

       let indexPath = NSIndexPath(forRow: row, inSection: section)
       var cell = tableView.cellForRowAtIndexPath(indexPath) 

       // do what you want with the cell

    }
}

关于ios - 如何在 Swift 中循环访问 UITableView 中的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29601294/

相关文章:

ios - UITableViewCell 内容在滚动时合并

arrays - 上传元组数组 Cloud Kit

ios - 将变量放在 AppDelegate 中是 Swift 中静态变量的解决方法吗?

iphone - 当应用程序运行 IOS 时,通过设置包更改应用程序设置

android - coco2d-x : java. lang.IllegalArgumentException: 无法找到 native 库

ios - 如何为 TableView 和 CollectionView 创建一个可重用的单元格

iPhone,如何修复此警告 : '-respondsToSelector:' not found in protocol(s)

ios - 为什么执行insertRows后,tableview numberOfRowsInSection不更新?

swift - 为什么在register方法中为tableview注册UITableViewCell时需要指定self?

iphone - 方向变化期间平滑的纵横比变化