已解答:请参阅下面的答案(和可能的解释)。为什么reloadRowsAtIndexPaths不适用于iOS 5.0?
我正在制作适用于iOS 5.1设备但不适用于iOS 5.0设备的应用程序。下面是故障代码,关于5.1,但不适用于5.0:
- (void) expandIndexPath: (NSIndexPath *) indexPath afterDelay: (BOOL) delay
{
NSIndexPath *oldSelectedIndexPath = [NSIndexPath indexPathForRow:self.mySelectedIndex inSection:0];
self.mySelectedIndex= indexPath.row;
// [self.myTableView beginUpdates];
[self.myTableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:[NSIndexPath indexPathForRow:self.mySelectedIndex inSection:0], oldSelectedIndexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
// [self.myTableView endUpdates];
}
更奇怪的是,它在安装iOS 5.0如果我[self.myTableView reloadData];
更换reloadRowsAtIndexPaths
线。为什么是这样? 5.0有没有关于reloadRowsAtIndexPaths行的错误?我试过它5.0和有没有begin/endUpdates
线,都没有工作。
编辑:更具体的,当我运行在iOS 5应用程序将其与下面的错误崩溃:
* Assertion failure in
-[_UITableViewUpdateSupport _computeRowUpdates]
,/SourceCache/UIKit/UIKit-1912.3/UITableViewSupport.m:386
[Switching to process 7171 thread 0x1c03]Terminating app due to uncaught exception '
NSInternalInconsistencyException
', reason: 'Invalid table view update. The application has requested an update to the table view that is inconsistent with the state provided by the data source.'
编辑:这是我的UITableViewDataSource方法。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//I am positive that this will ALWAYS return the number (it never changes)
return self.myCellControllers.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//I cache my table view cells, thus each time this method gets called it will
// return the exact same cell. Yes, I know that most of the time I should be dequeing
// and reusing cells; just trust me that this time, it's best for me to cache them
// (There are very few cells so it doesn't really matter)
CellController *controller = [self.myCellControllers objectAtIndex:indexPath.row];
return controller.myCell;
}
- numberOfSectionsInTableView: always returns 1;
唯一有趣的方法是
- (CGFloat)tableView:(UITableView *)aTableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row == self.mySelectedIndex)
{
return DEFAULT_CELL_HEIGHT + self.expandSize;
}
else
{
return DEFAULT_CELL_HEIGHT;
}
}
正如方案的这一部分是如何工作的,当用户点击一个细胞,细胞滚动到屏幕顶部的快速概述。在它位于屏幕顶部之后,其索引被设置为self.mySelectedIndex
,并且它展开(变高)。
始终将'-beginUpdates' /'-endUpdates'方法与'-reloadRowsAtIndexPaths:withRowAnimation:' – CodaFi 2012-07-18 20:24:47
一起使用定义“不适用于”。什么都没发生?异常抛出?用户从设备发出的激光束蒸发了吗? – benzado 2012-07-18 20:25:00
大声笑...抱歉没有更具体。它崩溃,出现以下错误:' - 断言失败 - [_ UITableViewUpdateSupport _computeRowUpdates],/SourceCache/UIKit/UIKit-1912.3/UITableViewSupport.m:386 终止应用程序由于未捕获的异常'NSInternalInconsistencyException',原因:'无效的表视图更新。该应用程序已请求更新与表格视图不一致的数据源提供的状态。'' – Nosrettap 2012-07-18 20:27:21