为什么以下代码在 iOS 6 中运行良好。但在 iOS 5 中却陷入无限循环,导致设备崩溃。一旦执行“self.footerView = ...”行,它就会再次调用 viewForFooterInSection。因此将其陷入无限循环。
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
if (!self.footerView)
self.footerView = [[UIView alloc] initWithFrame:[tableView rectForFooterInSection:section]];
return self.footerView;
}
有更好的方法吗?为什么这在 iOS 6 上有效,但在 iOS 5 上不起作用?
问候,
彼得
最佳答案
很可能 rectForFooterInSection
正在调用委托(delegate)方法 tableView:viewForFooterInSection:
来计算 View 框架。
对我来说,这进入无限循环似乎是合理的(并且是预期的)。
您基本上是在告诉 x
部分的 footerView
是一个与 footerView
具有相同框架的 UIView
> 部分 x
,与您应该返回的完全相同。你能看到这里的递归问题吗?
显然,iOS 6 中存在一些实现更改,可以防止无限循环(可能依赖于页脚框架的某些默认值),但上面的委托(delegate)方法实现肯定是错误的。
您应该独立定义您的 footerView
并在委托(delegate)方法中返回它。
关于uitableview - viewForFooterInSection 陷入无限循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13754489/