我已经尝试了所有可能的方法,但我仍然无法弄清楚为什么数据没有显示在自定义单元格中。它在 subTitle
单元格中看起来不错,println
确认数据在那里。我已经检查了标识符和 IBOutlets
100 次:
// ActivityDetailsTableViewController.swift
// TestActForm
//
// Created by Jeremy Andrews on 2015/08/08.
// Copyright (c) 2015 Jeremy Andrews. All rights reserved.
//
import UIKit
class ActivityDetailsTableViewController: UITableViewController
{
var activities: [Activity] = activityProfile
override func viewDidLoad()
{
super.viewDidLoad()
}
override func didReceiveMemoryWarning()
{
super.didReceiveMemoryWarning()
}
// MARK: - Table view data source
override func numberOfSectionsInTableView(tableView: UITableView) -> Int
{
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return activities.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath)
-> UITableViewCell
{
let cell = tableView.dequeueReusableCellWithIdentifier("ActivityDetail", forIndexPath: indexPath) as! ActivityDetailCell
let activity = activities[indexPath.row] as Activity
println(activity.question)
cell.questionLabel?.text = activity.question
cell.answerLabel?.text = activity.answer
println(cell.questionLabel.text)
return cell
}
}
import UIKit
class ActivityDetailCell: UITableViewCell
{
@IBOutlet weak var questionLabel: UILabel!
@IBOutlet weak var answerLabel: UILabel!
override func awakeFromNib()
{
super.awakeFromNib()
// Initialization code
}
override func setSelected(selected: Bool, animated: Bool)
{
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
最佳答案
感谢所有提出建议的人 - 经过 2 天的努力,我终于找到了解决方案,感谢:creating custom tableview cells in swift .
您所要做的就是转到文件检查器 - 取消选中大小类 - 会有警告等。运行并且有数据 - 奇怪的是 - 返回文件检查器并再次检查“使用大小类”,运行和所有数据正确反射(reflect)。似乎在某些情况下边距设置为负数。 一个想法 - 如果 println( cell.nameLabel.text) 显示你的数据在那里,那么它就在那里,检查边距或将标签放在中心作为试验。
我之前注意到 Storyboard有一个与单元格边界不匹配的突出显示区域 - 这实际上显示了运行将使用的边界。我认为的一个错误
关于ios - 数据未显示在 swift 中的自定义 tableview 单元格中,添加了下面的单元格类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31891825/