我正在尝试制作一个包含多个部分的 TableView ,但由于某些(可能是愚蠢的)原因,只有第一部分在我的 TableView 中可见。
var labels = ["label1", "label2"]
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 2
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
var sectionHeader = ""
if section == 0 {
sectionHeader = "first section header"
} else if section == 1 {
sectionHeader = "second section header"
}
return sectionHeader
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! UITableViewCell
if indexPath.section == 0 {
cell.textLabel!.text = labels[0]
} else if indexPath.section == 1 {
cell.textLabel!.text = labels[1]
}
return cell
}
第一部分的标题与带有标签文本“label1”的单元格一起出现,但找不到第二部分。
是否有某种我没有设置的设置?我在这里做错了什么。
最佳答案
你的代码看起来不错,你可以检查的东西很少
1> Tableview 的框架不够大,无法容纳 2 个部分,而且它也不能滚动。
2> heightForRow 委托(delegate)方法或 viewForHeader 或 heightforHeader 返回 0 或 nil
3> 你的约束在运行时被打破,这就是为什么 tableview 不能正确显示的原因(你需要在运行时检查控制台)
您可以在运行时启动 XCode 的可视化调试器,看看您的 TableView 是否未被其他组件等隐藏...(调试 View 层次结构)
关于ios - 在表格 View 中看不到部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32175757/