Why is the array not showing up in the table view?

2019-08-17 03:24发布

I am appending data from parse into an array, but when I try to load array in table view nothing shows up. The array is populated, but nothing is showing up. How do I fix this?

class View2: UIViewController, UITableViewDataSource, UITableViewDelegate{

  var ret = [String]()

  func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

    return ret.count
  }

  func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    let cell = table.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) 

    cell.textLabel?.text = ret[indexPath.row]

    return cell
   }
}

4条回答
冷血范
2楼-- · 2019-08-17 03:52

in my case I forgot to connect the UITableView datasource outlet to the ViewController.

storyboard

查看更多
相关推荐>>
3楼-- · 2019-08-17 03:58

Add a call to reloadData() method of UITableView in the setter of your array.

查看更多
淡お忘
4楼-- · 2019-08-17 03:59

After set 'ret' value, you have to reload table.

In my case,

var ret = [String](){
    didSet{
        self.tableView.reloadData()
    }
}
查看更多
\"骚年 ilove
5楼-- · 2019-08-17 04:09

Ensure your tableview is being reloaded after you receive the data. Use tableViewName.reloadData()

查看更多
登录 后发表回答