很简单的问题,但我就是无法让它正常工作。当单击该部分中的单元格时,我需要能够访问该部分的字符串标题值。
我最初的尝试没有成功:
[tableView titleForHeaderInSection:1];
我认为这可行的原因是因为我也在使用这个:
[tableView cellForRowAtIndexPath:indexPath];
效果很好。我正在实现委托(delegate),但仍然收到 UITableView 可能不会响应 titleForHeaderInSection 的警告。然后由于无法识别的选择器而崩溃。
我需要做的就是将单元格标题的字符串值和部分标题传递到下一个 View 。
我做错了什么?有更好的方法吗?谢谢
最佳答案
您可以从 UITableViewController
和 UITableView
访问 titleForHeaderInSection
:您只需遵循对象链即可。
从 View Controller 开始的示例:
class TableViewController: UITableViewController {
func titleForHeaderInSection(indexPath:NSIndexPath) -> String? {
if let tableView = self.tableView {
if let dataSource = tableView.dataSource {
if dataSource.respondsToSelector("tableView:titleForHeaderInSection:") {
return dataSource.tableView!(tableView,
titleForHeaderInSection:indexPath.row)
}
}
}
return nil
}
}
关于iphone - 如何手动调用UITableView的titleForHeaderInSection方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6494745/