Uitableview viewForFooterInSection陷入无限循环
为什么以下代码在iOS 6中运行良好。但在iOS 5中,它陷入了无限循环,导致设备崩溃。执行行“self.footerView=…”后,它将再次调用ViewForFooterInstitution。因此,它被困在一个无限循环中Uitableview viewForFooterInSection陷入无限循环,uitableview,ios5,crash,ios6,infinite,Uitableview,Ios5,Crash,Ios6,Infinite,为什么以下代码在iOS 6中运行良好。但在iOS 5中,它陷入了无限循环,导致设备崩溃。执行行“self.footerView=…”后,它将再次调用ViewForFooterInstitution。因此,它被困在一个无限循环中 - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { if (!self.footerView) self.footer
- (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上运行
问候,
Peter很可能是
RectforFooterInstitution
调用委托方法tableView:ViewForFooterInstitution:
,以计算图幅
对我来说,这似乎是合理的(也是意料之中的),它进入了一个无限循环
您基本上是在告诉我们,节x
的footerView
是一个UIView
,与节x
的footerView
具有相同的框架,与您应该返回的框架完全相同。你能看到这里的递归问题吗
显然,ios6中的一些实现更改阻止了无限循环(可能依赖于页脚框架的一些默认值),但是上面的委托方法实现肯定是错误的
您应该独立定义
页脚视图
,并在委托方法中返回它。我遇到了这个问题。这种设置页脚的方法最适合我,因为我希望定期刷新页脚,而且有一个标签句柄很好。如果是递归,只需返回nil,apple就会帮助您计算出矩形(即使在iOS 4.3到5.1中)
static BOOL alreadyCheckingFooter = false;
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
if (!self.footerView) {
if (alreadyCheckingFooter)
return nil;
alreadyCheckingFooter = true;
self.footerView = [[UIView alloc] initWithFrame:[tableView rectForFooterInSection:section]];
alreadyCheckingFooter = false;
}
return self.footerView;
}