2011-02-05 31 views
0

我收到以下錯誤......Obj-C,如何在UITableView中顯示「找不到行」,並允許刪除所有行,出錯?

Terminating app due to uncaught exception NSInternalInconsistencyException, 
reason: Invalid update: invalid number of rows in section 0. The number of 
rows contained in an existing section after the update (1) must be equal to 
the number of rows contained in that section before the update (1), plus or 
minus the number of rows inserted or deleted from that section 
(0 inserted, 1 deleted). 

我只是增加了一些代碼來顯示一排說世界上沒有數據...

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

    NSInteger num = [self.transactionsArray count]; 

    if (num == 0) { 
     num = 1; 
     [dataTableView setEditing: FALSE animated: NO]; 
    } 
    return num; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView 
     cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    UITableViewCell *cell1; 
    if(transactionsArray.count == 0) { 
     self.navigationItem.leftBarButtonItem.enabled = FALSE; 
     cell1 = [[[UITableViewCell alloc] initWithStyle: 
       UITableViewCellStyleDefault reuseIdentifier:nil] autorelease]; 

     cell1.textLabel.text = @"No transactons found"; 
     return cell1; 
    } 
     //Normal processing 

我已經通過加強前產生錯誤,並在numberOfRowsInSection完成後發生。所以它發現,這是一個它並不期待的部分。

我該如何解決這個問題?

編輯: 繼承人只是錯誤

tableView:commitEditingStyle:forRowAtIndexPath:] [Line 630] commitEditingStyle start 
tableView:commitEditingStyle:forRowAtIndexPath:] [Line 633] Delete now! 
numberOfSectionsInTableView:] [Line 447] numberOfSectionsInTableView start 
numberOfSectionsInTableView:] [Line 447] numberOfSectionsInTableView start 
tableView:numberOfRowsInSection:] [Line 456] numberOfRowsInSection start 

回答

0

執行異常說什麼之前發生了什麼。當您撥打-deleteRowsAtIndexPaths:withRowAnimation:刪除表格中的所有行時,請插入-insertRowsAtIndexPaths:withRowAnimation:以使行數正確。

+0

我不能做任何事情後deleteRowsAtIndexPaths我只是得到錯誤 – Jules 2011-02-05 11:07:44

相關問題