iphone - 如何手动调用UITableView的titleForHeaderInSection方法?

标签 iphone uitableview delegates title sections

很简单的问题,但我就是无法让它正常工作。当单击该部分中的单元格时,我需要能够访问该部分的字符串标题值。

我最初的尝试没有成功:

[tableView titleForHeaderInSection:1];

我认为这可行的原因是因为我也在使用这个:

[tableView cellForRowAtIndexPath:indexPath];

效果很好。我正在实现委托(delegate),但仍然收到 UITableView 可能不会响应 titleForHeaderInSection 的警告。然后由于无法识别的选择器而崩溃。

我需要做的就是将单元格标题的字符串值和部分标题传递到下一个 View 。

我做错了什么?有更好的方法吗?谢谢

最佳答案

您可以从 UITableViewControllerUITableView 访问 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/

相关文章:

iphone - 发布新版本时更改已发布应用程序的包 ID

iphone - xcdatamodel 内容消失

ios - UITableView didSelectRowAt 无法获取我的单元格

c# - CreateDelegate() System.ArgumentException 方法签名不匹配

testing - 我如何使用 JustMock 来测试接口(interface)事件委托(delegate)

iphone - iOS 6 问题将 MPMediaItem 转换为 NSData

iphone - 如何在 ios 中使用 AudioQueue 编码/解码 speex

ios - 滚动后重用单元​​格后如何维护表格 View 单元格中的值?

ios - 使用自动布局时如何知道 UITableViewCell 的宽度?

swift - 我的委托(delegate)方法变成了 nil 而它不应该吗?