2013-03-20 78 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解決了問題。