How can I group TableView items from a dictionary in swift?

后端 未结 7 1445
灰色年华
灰色年华 2020-12-12 16:44

Lets consider this example:

import UIKit
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { 
    @IBOutlet weak var tableV         


        
7条回答
  •  爱一瞬间的悲伤
    2020-12-12 17:12

    Swift 2

    you dictionary example

    var dic:Dictionary = ["key":"value","key1":"value2"]
    

    Your table

     func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{
            let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! UITableViewCell
    
        var key   = Array(self.dic.keys)[indexPath.row]
        var value = Array(self.dic.values)[indexPath.row]
        cell.text = key + value 
    }
    

提交回复
热议问题