2016-11-08 72 views
0

我有我的ViewControllern數量的部分在我的第一部始終顯示我心願產品(僅基於顯示收藏在SettingsController啓用選項)每次UITableView當我一個產品添加到我的願望清單在我的DetailViewController我觸發NSNotificatiion到我的ViewController它將取回願望清單記錄。如何刷新特定部分?

numberOfRowsInSection:總是返回1,因爲它是一個UITableView + UICollectionView組合產生水平+ Vertial滾動。

所以,我重裝我的部分像下面這樣,

if (isWishListSectionReloadRequires) { 
    NSArray *deleteIndexPaths = [NSArray arrayWithObjects: 
           [NSIndexPath indexPathForRow:0 inSection:0], 
           nil]; 
    NSArray *insertIndexPaths = [NSArray arrayWithObjects: 
           [NSIndexPath indexPathForRow:0 inSection:0], 
           nil]; 
    [tableView beginUpdates]; 
    [tableView insertRowsAtIndexPaths:insertIndexPaths withRowAnimation:UITableViewRowAnimationNone]; 
    [tableView deleteRowsAtIndexPaths:deleteIndexPaths withRowAnimation:UITableViewRowAnimationNone]; 
    [tableView endUpdates]; 
} else { 
    [tableView reloadData]; 
} 

但是,我面臨崩潰之下,

斷言失敗 - [UITableView的_endCellAnimationsWithContext:]/SourceCache /UIKit_Sim/UIKit-2380.17/UITableView.m:1054 2016-11-04 04:25:15.921估計[9025:c07] ***因未捕獲異常'NSInternalInconsistencyException'而終止應用,原因:'無效更新:無效數量部分。更新後表格視圖中包含的節數(10)必須等於更新前表格視圖中包含的節數(10),加上或減去插入或刪除的節數(插入1次,1次刪除)

誰能告訴我可能是什麼原因?任何想法將不勝感激!

+1

您是否相應地更新了數據源?我的意思是在一個部分的行數等? – KrishnaCA

+0

@KrishnaChaitanyaAmjuri我如何手動更新數據源? – Praveenkumar

+0

嘗試 - (void)reloadSections:(NSIndexSet *)節withRowAnimation:(UITableViewRowAnimation)動畫,而不是刪除和插入。 – Sealos

回答

1

您可以改用UITableView的reloadSections方法。

目標C

NSRange range = NSMakeRange(0, 1); 
NSIndexSet *section = [NSIndexSet indexSetWithIndexesInRange:range];          
[self.tableView reloadSections:section withRowAnimation:UITableViewRowAnimationNone]; 

斯威夫特

tableView.reloadSections(NSIndexSet(index: 2), withRowAnimation: .None) 
0

您可以重新加載集合視圖,你只需要更新的心願。

[collectionView reloadData]; 

如果您需要在水平和垂直滾動有使用下面的方法很多第三方的lib一次結賬RTTwoDimmensionalScroll

0

刷新,不要忘記重新加載特定部分內開始更新,並最終更新,使頁眉和頁腳也得到更新。

[tableView beginUpdates]; 
NSIndexSet *section = [NSIndexSet indexSetWithIndex:0];          
[self.tableView reloadSections:section withRowAnimation:UITableViewRowAnimationAutomatic]; 
[tableView endUpdates];