swift表视图没有填充

use*_*707 1 uitableview swift

我在从数组中填充表格视图时遇到了一些麻烦.虽然我的数组不是空的(我尝试在控制台中打印它并且有我想要的数据),但tableView并没有填充我想要的东西,而是空的.我想知道我是否在这里做了任何错误导致这一点

这是我的代码:

func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return 1
}

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

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
   var cell = UITableViewCell()
    // display our ranked data
    cell.textLabel?.text = "\(tableData[indexPath.row])"
    return cell
}
Run Code Online (Sandbox Code Playgroud)

其中numberOfGamesPlayedRecently是一个int,而我的tableData是一个纪元时间数组

谢谢!

小智 5

我自己也遇到了同样的问题,偶然发现了你的问题.我能够通过以下方式解析我的tableView:

1.在类声明中将ViewController设置为UITableViewDataSource,
在ViewDidLoad方法中将ViewController设置为数据源,如下所示:tableView.dataSource = self