Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 未在小更新时从核心数据重新加载到tableview中的数据_Iphone_Objective C_Uitableview - Fatal编程技术网

Iphone 未在小更新时从核心数据重新加载到tableview中的数据

Iphone 未在小更新时从核心数据重新加载到tableview中的数据,iphone,objective-c,uitableview,Iphone,Objective C,Uitableview,我有一个基本的相册应用程序,在第一次查看时,会显示相册列表,并带有一个字幕,显示每个相册中有多少图像。我已经做好了添加相册和向相册中添加图像的一切工作。 问题是,每当应用程序加载时,图像计数行都是准确的,但我无法让它们在执行期间更新 加载应用程序时,以下viewdidload会正确填充tableview的所有行: - (void)viewDidLoad { [super viewDidLoad]; // Set the title. self.title = @"Pho

我有一个基本的相册应用程序,在第一次查看时,会显示相册列表,并带有一个字幕,显示每个相册中有多少图像。我已经做好了添加相册和向相册中添加图像的一切工作。 问题是,每当应用程序加载时,图像计数行都是准确的,但我无法让它们在执行期间更新

加载应用程序时,以下viewdidload会正确填充tableview的所有行:

- (void)viewDidLoad {
    [super viewDidLoad]; 
    // Set the title.
    self.title = @"Photo albums";

    // Configure the add and edit buttons.
    self.navigationItem.leftBarButtonItem = self.editButtonItem;

    addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addAlbum)];
    addButton.enabled = YES;
    self.navigationItem.rightBarButtonItem = addButton;

    /*
    Fetch existing albums.
    Create a fetch request; find the Album entity and assign it to the request; add a sort descriptor; then execute the fetch.
    */
    NSFetchRequest *request = [[NSFetchRequest alloc] init];
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Album" inManagedObjectContext:managedObjectContext];
    [request setEntity:entity];

    // Order the albums by name.
    NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"albumName" ascending:NO];
    NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
    [request setSortDescriptors:sortDescriptors];
    [sortDescriptor release];
    [sortDescriptors release];

    // Execute the fetch -- create a mutable copy of the result.
    NSError *error = nil;
    NSMutableArray *mutableFetchResults = [[managedObjectContext executeFetchRequest:request error:&error] mutableCopy];
    if (mutableFetchResults == nil) {
        // Handle the error.
    }

    LocationsAppDelegate *mainDelegate = (LocationsAppDelegate *)[[UIApplication sharedApplication] delegate];

    // Set master albums array to the mutable array, then clean up.
    [mainDelegate setAlbumsArray:mutableFetchResults];
    [mutableFetchResults release];
    [request release];
}
但当我在ViewDidDisplay中运行类似的代码时,什么也没有发生:

{
    /*
    Fetch existing albums.
    Create a fetch request; find the Album entity and assign it to the request; add a sort descriptor; then execute the fetch.
    */
    NSFetchRequest *request = [[NSFetchRequest alloc] init];
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Album" inManagedObjectContext:managedObjectContext];
    [request setEntity:entity];

    // Order the albums by creation date, most recent first.
    NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"albumName" ascending:NO];
    NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
    [request setSortDescriptors:sortDescriptors];
    [sortDescriptor release];
    [sortDescriptors release];

    // Execute the fetch -- create a mutable copy of the result.
    NSError *error = nil;
    NSMutableArray *mutableFetchResults = [[managedObjectContext executeFetchRequest:request error:&error] mutableCopy];
    if (mutableFetchResults == nil) {
        // Handle the error.
    }

    LocationsAppDelegate *mainDelegate = (LocationsAppDelegate *)[[UIApplication sharedApplication] delegate];

    // Set master albums array to the mutable array, then clean up.
    [mainDelegate setAlbumsArray:mutableFetchResults];
    [self.tableView reloadData];
    [mutableFetchResults release];
    [request release];  
}

如果我在其他地方错过了这个问题的答案,我深表歉意,但我错过了什么?

要排除故障,请在
-viewdide:
中的几个地方放置
NSLog
语句。您可以使用这些日志语句来确保正确调用此方法,并至少检查
mutableFetchResults
的内容。

谢谢,我没有在运行时保存要存储的数据,我只是在退出时保存更改。现在一切正常。