Scu*_*ool 89 crash objective-c uitableview ios
希望这将是一个快速解决方案.我一直试图弄清楚我一直在犯的错误.下面列出了错误,并且appdelagate低于该错误.
任何帮助表示赞赏.
谢谢
2012-04-12 21:11:52.669 Chanda [75100:f803] ---断言失败
-[UITableView _endCellAnimationsWithContext:],/SourceCache/UIKit_Sim/UIKit-1914.84/UITableView.m:10372012-04-12 21:11:52.671 Chanda [75100:f803] ---由于未被捕获的异常终止app'NSInternalInconsistencyException' ,原因:'无效更新:第0节中的行数无效.更新后的现有部分中包含的行数(2)必须等于更新前该部分中包含的行数(2),再加上或减去从该部分插入或删除的行数(插入1个,删除0个),加上或减去移入或移出该部分的行数(0移入,0移出).
#import "AppDelegate.h"
@implementation AppDelegate
@synthesize window = _window;
@synthesize databaseName,databasePath;
- (BOOL)application: (UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions {
self.databaseName = @"Customers.db";
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDir = [documentPaths objectAtIndex:0];
self.databasePath = [documentDir stringByAppendingPathComponent:self.databaseName];
[self createAndCheckDatabase];
return YES;
}
- (void)createAndCheckDatabase {
BOOL success;
NSFileManager *fileManager = [NSFileManager defaultManager];
success = [fileManager fileExistsAtPath:databasePath];
if (success) return;
NSString *databasePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:self.databaseName];
[fileManager copyItemAtPath:databasePathFromApp toPath:databasePath error:nil];
}
@end
Run Code Online (Sandbox Code Playgroud)
pbx*_*pbx 43
我没有看到你向我们展示这部分代码的原因.您的错误必须在我假设的代码中连接到此部分
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
Run Code Online (Sandbox Code Playgroud)
可能你在其中一个数据源方法中犯了一个错误.目前不可能说出究竟是什么错误,但我认为它可能是这样的:你正在告诉表视图,numberOfRowsInSection你想要保留n行和设置,cellForRowAtIndexPath然后在你那里只处理n - 1行.
很抱歉,这个答案不能像应有的那样精确.如果您向我们展示您的数据源实现,则可以更容易地了解正在发生的事情.
abb*_*ood 26
像孙子说的那样:没有战斗就最好赢.在我的情况下,每当我看到这种错误消息(即行添加删除之间的差异等)..我甚至没有调试任何东西..我只是避免在我重新加载行等的额外调用..这是99%的发生此错误的情况.
这是一个常见的情况,这个错误发生了:我有一个UINavigationController,它有一个UITableView,当我点击一行它推动一个新的UITableView,依此类推.当我弹出最后一个UITableview并返回到它UITableView之前,这个错误总是发生在我身上,此时我对该loadIt函数进行了不必要的调用,该函数基本上插入行并重新加载UITableView.
发生这种情况的原因是因为我错误地将我的loadIt函数放在viewDidAppear:animated而不是viewDidLoad.viewDidAppear:animated每次UITableView显示时viewDidLoad调用,只调用一次.
Olo*_*f_t 24
删除行时,请记住它还会在更新时检查部分:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)theTableView
Run Code Online (Sandbox Code Playgroud)
如果要删除作为节中最后一项的行,则需要删除整个节(否则可能会导致节数错误并抛出此异常).
不要忘记更新确定numberOfRowsInSection的数组.它需要在动画和删除之前更新
我们检查部分中的行数是否为1,因为我们必须删除整个部分.
如果有人能让这个答案更清楚,请纠正我.
[self.tableView beginUpdates];
if ([tableView numberOfRowsInSection:indexPath.section] == 1) {
[tableView deleteSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationFade];
} else {
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
}
[self.tableView endUpdates];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
72328 次 |
| 最近记录: |