2015-04-13 6 views
0

Я использую Alamofire Library для http-запроса.Как перебрать данные в UITableView в Swift

Я знаю, как цикл в обычном текстовом поле:

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++ 
} 

Но как я это делаю в виде таблицы?

+0

, что хотите ли вы туда петлиться? вы хотите, чтобы петля * внутри * табличное представление? Что делать? – luk2302

+0

Вы хотите закодировать UITableViewCells в UITableView? –

+0

@ luk2302 да, я хочу, чтобы петля UITableViewCells в виде таблицы –

ответ

3

Вы можете перебрать 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 

    } 
} 
0

Вот как вы можете цикл throgh клеток, которые в настоящее время видны:

let indexpaths = indexPathsForVisibleRows()! 
    let totalVisibleCells = indexpaths.count - 1 
    if totalVisibleCells <= 0 { return } 

    for index in 0...totalVisibleCells { 
     let indexPath = indexpaths[index] as! NSIndexPath 
     if let cell = cellForRowAtIndexPath(indexPath) { 

       // Do your cell modifications here... 

     } 
    } 
1

Swift 2,2

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 

       } 
      } 
Смежные вопросы