为什么断言失败 - [UISectionRowData refreshWithSection:tableView:tableViewRowData:]?

use*_*201 5 iphone uitableview

 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'
Run Code Online (Sandbox Code Playgroud)

我的代码

 -(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];

}
Run Code Online (Sandbox Code Playgroud)

我没有得到这个问题?

k06*_*06a 8

检查你的tableView:heightForRowAtIndexPath:.也许你会返回类似NaN/ +inf/ -inf而不是高度的东西.那是我的错.

请记住,这不是崩溃doublefloat类型除以零:

double d = 5.0;
double r = d/0.0;
Run Code Online (Sandbox Code Playgroud)

所以这可以帮助你:

if (isnan(r) || isinf(r)) {
    // ...
}
Run Code Online (Sandbox Code Playgroud)


raf*_*tta 5

我也失败了-[UISectionRowData refreshWithSection:tableView:tableViewRowData:]。在我的情况下,这是由于estimatedRowHeight在使用时设置太小而引起的:

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    return UITableViewAutomaticDimension
}
Run Code Online (Sandbox Code Playgroud)

用于自动调整tableView的单元格。设置estimatedRowHeight2.0代替1.0解决的问题。