2014-10-27 44 views
7

我的應用程序在調用方法[tableView reloadData]表視圖後崩潰。這發生在刪除單行tableview(具有表視圖默認刪除行爲)並調用[tableView reloadData],然後在此代理numberOfSectionsInTableView應用程序崩潰並顯示我崩潰消息[UITableViewCell _setDeleteAnimationInProgress : ] : message sent to deallocated instance後,我Google搜索,但無法獲得健康的響應。如果有人遇到這種情況,那麼請幫助解決這個問題。下面是我的代碼。應用程序崩潰在tableview的reloadData方法

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ 
    return 2; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    if(section==0) 
     return [[dbSingleton sharedInstance] get_players_count]; 
    else if(section==1) 
     return 0; 
} 

- (NSString)tableView:(UITableView)tableView titleForHeaderInSection:(NSInteger)section{ 
    if(section==0) 
     return @"Player Detail"; 
    return nil; 
} 

- (UITableViewCellEditingStyle)tableView:(UITableView)tableView editingStyleForRowAtIndexPath:(NSIndexPath)indexPath{ 
    if(indexPath.section==1) 
     return UITableViewCellEditingStyleNone; 
    else 
     return UITableViewCellEditingStyleDelete; 
    } 
} 

-(CGFloat)tableView:(UITableView)tableView heightForRowAtIndexPath:(NSIndexPath)indexPath{ 
    return 44; 
} 

尋找答覆。提前致謝。

+0

您是否正在更新數據源? – jsetting32 2014-10-27 13:18:16

+0

請發佈完整的堆棧跟蹤。 – 2014-10-27 13:29:05

+2

我會說當你通過你的tableView委託方法刪除行時[[dbSingleton sharedInstance] get_players_count]沒有被更新。 – miya 2014-10-27 13:51:33

回答

12

最後,我找到了解決辦法。我做錯了的是,我正在調用方法reloadData上的commitEditingStyle,它的平均重新加載數據之前刪除行,如在回答This Thread中所述。我希望這也能幫助其他人。 感謝您的參與。

-1

[tableView Reload]產生崩潰,那麼它肯定會在數據源中出現問題,所以我認爲在tableview部分添加斷點並檢查是否正確更新數據源,否則顯示完整的崩潰消息。

+0

@答覆,感謝您的回答,但我發現解決方案善意研究我的答案。 – josh 2014-10-28 08:07:22

相關問題