2013-03-20 79 views
4
Assertion failure in -[UISectionRowData refreshWithSection:tableView:tableViewRowData:], /SourceCache/UIKit/UIKit-2380.17/UITableViewRowData.m:400 

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException',  reason:'Failed to allocate data stores for 997008923 rows in section 0. Consider using fewer rows' 

我的代码为什么声明失败 - [UISectionRowData refreshWithSection:tableView:tableViewRowData:]?

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
    { 

    return 1; 

    } 


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 

{ 

    return [appDelegate.purchaseArray count]; 

} 



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath 
    { 
    static NSString *CellIdentifier = @"cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault   reuseIdentifier:CellIdentifier]; 
    } 
    return cell; 
}  

-(void)viewWillAppear:(BOOL)animated 
{ 

    [cartTbl reloadData]; 

} 

我没有得到什么这是问题吗?

+0

不幸的是,当您创建/修改它们时,Apple不会仔细检查许多UI对象上的参数,并且在检测到不一致时选择不使用信息性错误消息。但基本上这个断言意味着你已经在你的表格控件中隐藏了一些东西。首先确保你已经设置了'delegate'和'dataSource'。 – 2013-03-20 12:04:53

+0

但仔细检查后,请参阅“无法为第0部分中的997008923行分配数据存储。请考虑使用更少的行”。我怀疑purchaseArray.count实际上有很多行,但不知何故该值必须被忽略。在numberOfRowsInSection中添加一个NSLog以记录返回值。 – 2013-03-20 12:09:02

+0

它在模拟器中运行正常,但不能在设备上运行。 – user2071201 2013-03-20 12:29:34

回答

7

查看您的tableView:heightForRowAtIndexPath:。也许你正在返回类似NaN/+inf/-inf而不是身高。那是我的错误。

记住,这是不是死机了doublefloat类型除以零:

double d = 5.0; 
double r = d/0.0; 

因此,这可以帮助你:

if (isnan(r) || isinf(r)) { 
    // ... 
} 
0

return [appDelegate.purchaseArray count];看起来像一个垃圾值。确保它已初始化。

1

由于其他原因,我出现了这样的错误。 我的应用工作正常,当我决定改变我的视图模型(我绑定我的表的对象)的东西。我删除了一个属性,并重新编译。突然,该应用程序抛出此错误。

事实证明,编译器没有捕获的代码中仍然存在对被删除属性的引用。我已经清理并重建了好几次,编译器从未发现我错过的错误。

重新启动xcode使构建失败,现在将违规行突出显示为错误。一旦我修好了,一切都很好。

如果遇到像这样的错误访问错误,并在调试器中看到奇怪的东西,比如应该将值赋给其他属性的属性,那么你可能会遇到一个错误,应该让你的编译只是编译xcode而已没有想到。重启可能会修复它 - 这是值得一试的。

1

我也在-[UISectionRowData refreshWithSection:tableView:tableViewRowData:]失败。

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { 
    return UITableViewAutomaticDimension 
} 

为自动调整大小的tableView的细胞:在我的情况下,它被设置太小estimatedRowHeight同时使用造成的。 设置estimatedRowHeight改为2.0而不是1.0解决了问题。