How to fill UITableView with a data from Dictionary. Swift

后端 未结 3 676
臣服心动
臣服心动 2020-12-21 11:54

Please help me with filling table view cells with data from a dictionary. For instance, I have cell like so:

and for filling it with data I\'ve started with

3条回答
  •  长情又很酷
    2020-12-21 12:11

    By using this:

    var valueArray: [Int] = []
    var currencyArray: [String] = []
    override func viewDidLoad() {
        super.viewDidLoad()
    
        for (key, value) in currencies! {
            print("key is - \(key) and value is - \(value)")
            currencyArray.append(key)
            valueArray.append(value)            
        }
    
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "CurrencyCell", for: indexPath) as! CurrencyCell
    
        //retrieve the key and value
        let value = valueArray[indexPath.row]
        let key = currencyArray[indexPath.row]
    
        //next use the value and key for what you need them
    
        return cell
    }
    

提交回复
热议问题