How can I loop through UITableView's cells?

前端 未结 8 1188
时光说笑
时光说笑 2020-12-07 13:04

I have n sections (known amount) and X rows in each section (unknown amount. Each row has a UITextField. When the user taps the \"Done\" button I want to iterate through eac

8条回答
  •  南笙
    南笙 (楼主)
    2020-12-07 13:40

    Accepted answer in swift for people who do not know ObjC (like me).

    for section in 0 ..< sectionCount {
        let rowCount = tableView.numberOfRowsInSection(section)
        var list = [TableViewCell]()
    
        for row in 0 ..< rowCount {
            let cell = tableView.cellForRowAtIndexPath(NSIndexPath(forRow: row, inSection: section)) as! YourCell
            list.append(cell)
        }
    }
    

提交回复
热议问题