Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/101.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
Ios 如何在UITableView中显示核心数据的数据_Ios_Objective C_Uitableview_Core Data - Fatal编程技术网

Ios 如何在UITableView中显示核心数据的数据

Ios 如何在UITableView中显示核心数据的数据,ios,objective-c,uitableview,core-data,Ios,Objective C,Uitableview,Core Data,我从JSON获得响应,并使用核心数据存储该数据。我希望始终在UITableView中显示数据。您能建议我如何在UITableView中显示数据吗 这是我正在使用的代码 NSManagedObject * newEntry =[[NSManagedObject alloc]initWithEntity:entityDesc insertIntoManagedObjectContext:self.managedObjectContext]; [newEntry setValue:[

我从JSON获得响应,并使用核心数据存储该数据。我希望始终在UITableView中显示数据。您能建议我如何在UITableView中显示数据吗

这是我正在使用的代码

    NSManagedObject * newEntry =[[NSManagedObject alloc]initWithEntity:entityDesc insertIntoManagedObjectContext:self.managedObjectContext];

    [newEntry setValue:[dict objectForKey:@"albumName"] forKey:@"albumName"];
    [newEntry setValue:[dict objectForKey:@"coverPhotoURL"] forKey:@"coverPhotoURL"];
    [newEntry setValue:[dict objectForKey:@"createdDate"] forKey:@"createdDate"];

    NSLog(@"Log %@", newEntry);

    NSError * error = nil;
    if ([self.managedObjectContext save:&error] == NO)
    {
        NSLog(@"CANNOT SAVE: %@ %@", error, [error localizedDescription]);
    }
    else {
        NSLog(@"SUCCES, go check the sqlite file");
    }
}


NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];    
NSEntityDescription *entity = [NSEntityDescription entityForName:@"GetAlbums"
                                          inManagedObjectContext:self.managedObjectContext];
[fetchRequest setEntity:entity];

NSError* error;    
NSArray *fetchedRecords = [self.managedObjectContext executeFetchRequest:fetchRequest error:&error];
NSLog(@"Fetch Records %@",fetchedRecords);

您可以使用下面的表视图方法来显示数据

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return  [self.arrayOfyourData count];
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"CellIdentifier";

    //you could use default cell or ur own custom cell.
    cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

    // Now here you could pare your self.arrayOfyourData to fetch and populate your cell.

    return cell;
}

即使如walle84所建议的,您可以实现UITableViewDelegate的方法来在表视图中显示数据,正确的方法是将UITableView与。如文件中所述,后者被使用

有效管理从核心数据获取请求返回的结果,以便为UITableView对象提供数据

我把重点放在效率上,因为它提供了很多优点。例如,它允许延迟加载数据,允许跟踪实现NSFetchedResultsControllerDelegate的特定实体的更改,等等

从哪里开始?有很多啧啧称奇的人。只要谷歌一下,你就会找到一个好的起点


你知道如何使用UITableViewController吗?是的,我知道TableView。你已经有了一系列获取的记录,那么就在表视图中显示它们吧。-你的问题是如何从数组中提取元素吗?我只写了[self.tableView reloadData];您是否阅读过本教程: