Ios UITableView部分标题故障?
我有一个视图控制器,里面有一个分组的tableview。这会产生一个非常奇怪的小故障,导致sectionTitles显示在侧面。我已经为tableview的superview附加了top、trailing、bottom和leading约束,并测试了在cellForRowAtIndexPath中返回UITableViewCell()以查看是否是单元格导致了问题,但它仍然显示为这样Ios UITableView部分标题故障?,ios,swift,uitableview,sections,Ios,Swift,Uitableview,Sections,我有一个视图控制器,里面有一个分组的tableview。这会产生一个非常奇怪的小故障,导致sectionTitles显示在侧面。我已经为tableview的superview附加了top、trailing、bottom和leading约束,并测试了在cellForRowAtIndexPath中返回UITableViewCell()以查看是否是单元格导致了问题,但它仍然显示为这样 var sectionTitles = ["Customer Orders", "Unprocessed Orders
var sectionTitles = ["Customer Orders", "Unprocessed Orders", "Processed Orders"]
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return sectionTitles.count
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
func sectionIndexTitlesForTableView(tableView: UITableView) -> [String]? {
return sectionTitles
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{
let cell = tableView.dequeueReusableCellWithIdentifier(CONSTANTS.CELL_IDENTIFIERS.ORDER_CELL) as! OrderTableViewCell
return cell
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
// Perform segue to order list in future
}
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return 117.0
}
几个小时后,我发现我没有实现这个方法
override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return sectionTitles[section]
}
几个小时后,我发现我没有实现这个方法
override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return sectionTitles[section]
}
如果你只有一个部分,你不会放很多标题。
如果您想为每个单元格指定标题,则必须在自定义的tableViewCell中添加一个标签,并在cellForRowAtIndexPath
中添加类似的内容(创建NSObject
类后):
如果你只有一个部分,你不会放很多标题。
如果您想为每个单元格指定标题,则必须在自定义的tableViewCell中添加一个标签,并在cellForRowAtIndexPath
中添加类似的内容(创建NSObject
类后):
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{
let cell = tableView.dequeueReusableCellWithIdentifier(CONSTANTS.CELL_IDENTIFIERS.ORDER_CELL) as! OrderTableViewCell
let order = Order[indexPath.row]
cell.yourTitleLabel.text = order.title
return cell
}