1

当我将数据添加到我的 tableViews 数据源(自定义对象数组)时,唯一显示的是 textLabel,而不是 detailTextLabel 或附件。我有什么配置错误吗?我在我的代码中做错了吗?我需要在我的代码中添加更多内容吗?

这是整个 ViewController 的代码(不包括添加新项目的警报):

class ObjectiveViewController: UIViewController, UITableViewDataSource {
@IBOutlet weak var tableView: UITableView!
var objectiveArray = [Objective]()

override func viewDidLoad() {
    super.viewDidLoad()
}

// MARK: UITableViewDataSource
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return objectiveArray.count
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("ObjectivePrototypeCell") as UITableViewCell
    cell.textLabel.text = objectiveArray[indexPath.row].name
    if objectiveArray[indexPath.row].hours == 0 {
        cell.detailTextLabel!.text = String(objectiveArray[indexPath.row].minutes) + ":" + String(objectiveArray[indexPath.row].seconds)
    } else {
        cell.detailTextLabel!.text = String(objectiveArray[indexPath.row].hours) + ":" + String(objectiveArray[indexPath.row].minutes) + ":" + String(objectiveArray[indexPath.row].seconds)
    }
    return cell
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

这是原型单元的配置方式:

原型单元配置。

这是原型在我的故事板中的外观:

我的故事板中的原型单元

这是我在表格中添加新单元格时的结果:

将新目标添加到我的表后的结果

4

0 回答 0