0

我的表格视图有问题。我正在保存从核心数据库中的 Web 服务返回的所有数据。我实现了一个下拉刷新功能来刷新我的表格视图。当应用程序第一次启动时,一切都很好。所有数据都显示在表格视图中,我可以根据需要多次刷新。

我遇到的问题是,当应用程序重新启动时,我希望它自动刷新 tableview。所以我把它放在了我的 viewDidLoad 中。

- (void)viewDidLoad
{
      [self checkForWIFIConnection];
    if (!self.genkDatabase) {
        NSURL *url = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
        url = [url URLByAppendingPathComponent:@"Default appGenk Database"];
        // url is now "<Documents Directory>/Default Photo Database"
        self.genkDatabase = [[UIManagedDocument alloc] initWithFileURL:url]; // setter will create this for us on disk
    }

     pull = [[PullToRefreshView alloc] initWithScrollView:(UIScrollView *) self.tableView];
    [pull setDelegate:self];
    [self.tableView addSubview:pull];
    [super viewDidLoad];
}

此方法将查看是否已创建数据库。在此方法之后,它转到以下函数UseDocument

- (void)useDocument
{
    if (![[NSFileManager defaultManager] fileExistsAtPath:[self.genkDatabase.fileURL path]]) {
        // does not exist on disk, so create it
        [self.genkDatabase saveToURL:self.genkDatabase.fileURL forSaveOperation:UIDocumentSaveForCreating completionHandler:^(BOOL success) {
            NSLog(@"no database created yet");
             [self fetchNewsIntoDocument:self.genkDatabase];
           [self setupFetchedResultsController];
        }];
    } else if (self.genkDatabase.documentState == UIDocumentStateClosed) {
        // exists on disk, but we need to open it
        NSLog(@"closed");
        [self.genkDatabase openWithCompletionHandler:^(BOOL success) {
            if([self checkForData] == YES){
                NSLog(@"there is data in viewdidload");
                [self emptyNews];
                [self fetchNewsIntoDocument:self.genkDatabase];
            }
            [self setupFetchedResultsController];

        }];
    } else if (self.genkDatabase.documentState == UIDocumentStateNormal) {
        // already open and ready to use
        [self setupFetchedResultsController];
    }
}

这个方法要做的,就是查看文档的状态。重新启动应用程序后,文档将关闭。那么我要检查是否有数据。如果有,我将删除所有内容并再次将其全部提取到数据库中。这也有效。

问题 我现在的问题是它只在屏幕上显示特定时刻的单元格。所以当我向下滚动时,我得到空单元格。就像您在下面的屏幕截图中看到的那样。

在此处输入图像描述

我也收到此错误。

*** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-2372/UITableView.m:1054
2012-12-26 09:34:54.831 Krc Genk[24584:c07] CoreData: error: Serious application error.  An exception was caught from the delegate of NSFetchedResultsController during a call to -controllerDidChangeContent:.  Invalid update: invalid number of sections.  The number of sections contained in the table view after the update (0) must be equal to the number of sections contained in the table view before the update (1), plus or minus the number of sections inserted or deleted (0 inserted, 0 deleted). with userInfo (null)

希望任何人都可以帮助我。

亲切的问候

4

1 回答 1

0

错误定义明确,您应该知道哪里出错了。它是部分的数量。

于 2012-12-26T08:36:57.490 回答