【发布时间】:2012-04-25 11:08:17
【问题描述】:
希望这将是一个快速修复。我一直在试图找出我不断遇到的错误。错误在下面列出,appdelagate 在下面。
感谢任何帮助。
谢谢
2012-04-12 21:11:52.669 Chanda[75100:f803] ---
-[UITableView _endCellAnimationsWithContext:],/SourceCache/UIKit_Sim/UIKit-1914.84/UITableView.m:1037中的断言失败 2012-04-12 21:11:52.671 Chanda[75100:f803] --- 由于未捕获的异常“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
【问题讨论】:
-
您应该将该代码移动到类中,并可能在后台线程中执行它。无论如何,当您尝试删除行而不实际减少表视图的数据源提供的行数时,通常会出现此错误。当您删除行时,您实际上是在删除数据吗?如果你不删除任何行,你能提供你的表格视图数据源实现吗?
标签: objective-c ios uitableview crash