I Want to load the Table data from a NSDictionary object. This is how i did below function to fetch numberofRows. how to set the value for the cell from NSDictionary object ?
请给我解决方案,我是Objective C编程的初学者
以下是我从 coredata 获取的 NSDictionary 对象“obj”。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Pictures" inManagedObjectContext:managedObjectContext];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:entity];
[request setResultType:NSDictionaryResultType];
[request setReturnsDistinctResults:YES];
[request setPropertiesToFetch:@[@"title"]];
// Execute the fetch.
NSError *error;
objects = [managedObjectContext executeFetchRequest:request error:&error];
if (objects == nil) {
// Handle the error.
}
for( obj in objects ) {
NSLog(@"Title: %@", [obj objectForKey:@"title"]);
}
return [objects count];
}
在单元格中,我想添加 NSdictionary 对象中的标题。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
return cell;
}