【发布时间】:2012-01-09 09:40:28
【问题描述】:
我有以下代码,我相信NSFetchRequest 实际上是在工作,但在viewWillAppear 运行后,我的 tableView(peopleList) 中没有任何显示。
-(void)viewWillAppear:(BOOL)animated{
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
NSManagedObjectContext *moc = [appDelegate managedObjectContext];
NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"Person"
inManagedObjectContext:moc];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:entityDescription];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"firstName" ascending:YES];
[request setSortDescriptors:[NSArray arrayWithObject:sortDescriptor]];
NSError *error = nil;
NSLog(@"Count for request is %a", [moc countForFetchRequest:request error:&error]);
personArray = [moc executeFetchRequest:request error:&error];
[peopleList reloadData];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:cellIdentifier];
}
NSString *cellValue = [personArray objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue;
return cell;
}
以防万一,我的情节提要如图所示。
我的控制台显示“请求计数为 23”,这让我认为故障在于让数组本身显示在界面中。需要做什么才能让我的 personArray 出现在 peopleList 中?
感谢任何帮助。
【问题讨论】:
标签: iphone ios tableview xcode4.2 storyboard