objective-c - iOS UITableView numberOfRowsInSection 错误访问

标签 objective-c ios cocoa-touch uitableview

我在 heightForRowAtIndexPath 内部调用 UITableView 委托(delegate)的 numberOfRowsInSection 方法,但它给了我一个错误访问错误:

- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    ...
    NSLog(@"number of rows in section: %i", [tableView numberOfRowsInSection:[indexPath section]]);
    ...
}

谁能告诉我这里出了什么问题?

最佳答案

您正在调用委托(delegate)方法。

当您调用此方法时,它会调用相关的委托(delegate)方法,如cellForRowAtIndexPathheightForRowAtIndexPath 等。

它会导致无限循环,这就是它崩溃的原因。

关于objective-c - iOS UITableView numberOfRowsInSection 错误访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13912540/

相关文章:

cocoa - 如何创建颜色选择器轮 slider ?

ios - 从 MusicSequence 生成 MIDI 文件时遇到问题

ios - XIB 弹出窗口显示

iphone - UITextField setAutocapitalizationType 奇怪的行为

ios - 将标签包裹在 UIbutton 周围

ios - 现有的iOS表单框架

iphone - 添加 subview 后未收到touchesEnded/Moved/Cancelled

ios - 仅水平设置 CAGradientLayer 动画

iphone - 在 iPad 上按顺序加载多张图像

ios - 使用具有带 FlowLayout 的 UICollectionView 的单元格滚动 UITableView 时,应用程序崩溃