调整uitableview [英] Reranging a uitableview
问题描述
我遇到了与以下问题相同的问题:尝试移动时发生崩溃UITableView行!
我要做的就是对特定的重排操作插入一个新单元格或删除所选的单元格。
I ran into the same problem as desciped in: Crashing while trying to move UITableView rows! All I want to do is on specific reranging operations insert a new cell or delete the selected one.
有时我会得到:
*********-[_ UITableViewUpdateSupport _setupAnimationForReorderingRow],/ SourceCache / UIKit / UIKit-963.10 / UITableViewSupport.m:295的声明失败b $ b为单元格异常创建两个动画
********* Assertion failure in -[_UITableViewUpdateSupport _setupAnimationForReorderingRow], /SourceCache/UIKit/UIKit-963.10/UITableViewSupport.m:295 Attempt to create two animations for cell exception
,当我想通过调用 [self .tableView reloadData]
我得到:
and when I want to reload my data by calling [self.tableView reloadData]
I get:
**********由于未捕获的异常 NSRangeException而终止应用程序,原因: ***-[NSCFArray objectAtIndex:]:超出范围(0)的索引(0)
********** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSCFArray objectAtIndex:]: index (0) beyond bounds (0)'
外面有人知道如何处理这个问题吗?
Is there anybody out there who knows how to handle this problem?
推荐答案
再次晕!
感谢您的所有帮助!
我实际上找到了解决问题的方法!
Thanks for all your help! I actually found a solution for my problem!
我不在乎在编辑时动画化表格视图!
我终于在这篇文章中找到了一个解决方案:如何阻止UITableView moveRowAtIndexPath在重新排序时保留空白行
I don't care about animating the tableview while editing anymore! I finally found a solution in this post: How to stop UITableView moveRowAtIndexPath from leaving blank rows upon reordering
汤姆·萨克斯顿(Tom Saxton)说:
Tom Saxton said:
// APPLE_BUG:如果将单元格移到屏幕外的行(因为目标
//已被修改),则会创建假单元格并最终会导致崩溃
// APPLE_BUG: if you move a cell to a row that's off-screen (because the destination // has been modified), the bogus cell gets created and eventually will cause a crash
所以我的代码如下:
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
if( fromIndexPath == toIndexPath ) {
return;
}
if (toIndexPath.row == [self.data count] -1) { //element has been dragged to the bottom
self.data removeObjectAtIndex:fromIndexPath.row];
[self performSelector:@selector(delayedReloadData:) withObject:tableView afterDelay:0];
}
else { //Normal reoder operation
[self.data removeObjectAtIndex:fromIndexPath.row];
[self.data insertObject:element atIndex:toIndexPath.row];
}
}
- (void)delayedReloadData:(UITableView *)tableView {
//Assert(tableView == self.tableView);
[self.tableView reloadData];
}
我也有一个回忆我的initData方法泄漏,我这样解决:
I also had a mem leak in my initData method, which I solved like this:
-(void) initData {
if (!self.data) {
self.data = [[NSMutableArray alloc] init];
}
else {
[self.data removeAllObjects];
}
[self.data addObjectsFromArray:[self.fetchedResultsController fetchedObjects]];
}
感谢您的所有帮助!
尼古拉
这篇关于调整uitableview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!