Ios 如何在Swift中使用textLabel.text向表格视图对象显示单元格内容

Ios 如何在Swift中使用textLabel.text向表格视图对象显示单元格内容,ios,uitableview,swift,Ios,Uitableview,Swift,我想向textLabel.text属性添加一个简单字符串,然后在本例中的单元格中显示它 我添加了节数,该节中的行数,现在尝试向单元格显示数据 import UIKit class ViewController: UIViewController, UITableViewDataSource { // number of sections in table view func numberOfSectionsInTableView(tableView: UITableView) -> I

我想向textLabel.text属性添加一个简单字符串,然后在本例中的单元格中显示它

我添加了节数,该节中的行数,现在尝试向单元格显示数据

import UIKit

class ViewController: UIViewController, UITableViewDataSource {

// number of sections in table view
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return 1
}

// number of rows in section
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return 5
}

// returns the content of each row
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    // an object to represent each cell
    var cell = UITableViewCell()
    // configure
    cell.textLabel?.text? = "Hello"       - this is where i run into a problem
    //cell.textLabel?.text = "Hello"      - this is where i run into a problem
    return cell
}

ViewController未配置为代理

你到底有什么问题?您当前的代码会产生什么结果?您注释掉的行(文本上没有“?”)对我来说很好。问题:单元格不返回任何数据。结果:表格视图中只有无数行。为了测试上面的那一行,我注释掉了这一行,但是这两行都不起作用。你的注释行应该可以起作用。正在调用分区中的numberOfRowsInSection吗?