2016-11-08 26 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];