【问题标题】:Why is the array not showing up in the table view?为什么数组没有显示在表格视图中?
【发布时间】:2016-02-05 20:45:02
【问题描述】:

我正在将 parse 中的数据附加到一个数组中,但是当我尝试在表视图中加载数组时,什么都没有显示。数组已填充,但没有显示任何内容。我该如何解决这个问题?

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

【问题讨论】:

  • var ret = [String]() 这一行在哪里?你的 ret 有什么?你能告诉我们吗?

标签: ios arrays swift uitableview deque


【解决方案1】:

在我的例子中,我忘记将 UITableView 数据源出口连接到 ViewController。

【讨论】:

    【解决方案2】:

    设置'ret'值后,你必须重新加载表。

    就我而言,

    var ret = [String](){
        didSet{
            self.tableView.reloadData()
        }
    }
    

    【讨论】:

      【解决方案3】:

      在数组的设置器中添加对UITableViewreloadData() 方法的调用。

      【讨论】:

        【解决方案4】:

        确保在您收到数据后重新加载您的 tableview。使用tableViewName.reloadData()

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-09-18
          • 1970-01-01
          • 1970-01-01
          • 2022-01-21
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多