objective-c - -[UITableView _endCellAnimationsWithContext :] 中的断言失败

标签 objective-c ios uitableview crash

希望这将是一个快速修复。我一直在试图找出我不断遇到的错误。错误在下面列出,appdelagate 在下面。

感谢任何帮助。

谢谢

2012-04-12 21:11:52.669 Chanda[75100:f803] --- Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-1914.84/UITableView.m:1037 2012-04-12 21:11:52.671 Chanda[75100:f803] --- Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (2) must be equal to the number of rows contained in that section before the update (2), plus or minus the number of rows inserted or deleted from that section (1 inserted, 0 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).'

#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

最佳答案

我看不出您向我们展示这部分代码的原因。您的错误必须与我假设的代码中的这一部分有关

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

您可能在其中一种数据源方法中犯了错误。目前不可能说出究竟是什么问题,但我认为可能是这样的:您正在告诉 numberOfRowsInSection 中的 TableView 您希望保留 n 行并且设置并在 cellForRowAtIndexPath 中,然后您只处理 n - 1 行。

很抱歉,这个答案可能不够准确。如果您向我们展示您对数据源的实现,则更容易了解发生了什么。

关于objective-c - -[UITableView _endCellAnimationsWithContext :] 中的断言失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10134841/

相关文章:

objective-c - 如何为 Mac 创建 Cocoa 应用程序首选项?

ios - 类型 'UIImagePickerControllerSourceType' 没有成员 'photoLibrary'

ios - 不能使用 UITableViewAutomaticDimension 在 UITableView 中隐藏节标题

ios - DidSelectRowAtIndexPath SWIFT

ios - 关于创建新的 tableView 单元格,Apple 术语 "registers"是什么意思?

iphone - 检查数组是否包含特定属性的对象,objective-c

ios - MoPub 如何使用具有动态单元格高度的 MPTableViewAdPlacer 实现 iOS 原生广告?

ios - 如何从根 Controller ios 应用程序显示 View

ios - UIImageView 的占位符变量

ios - NSBundle 和 CFbundle 有什么区别?