2014-05-07 46 views
0

我有一个表格视图与自定义单元格,我试图填充保存在核心数据存储中的数据。我得到正确数量的单元格出现,但它们是空白的。下面的鳕鱼就是我用来调用细胞的东西。我确实发现了几个与此类似的问题,但在我的情况下没有任何帮助。自定义表单元格加载空白

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:   (NSIndexPath*)indexPath 
{ 

static NSString *CellIdentifier = @"WTHAITableViewCell"; 
WTHAITableViewCell *cell = (WTHAITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
NSManagedObject *location = [locations objectAtIndex:indexPath.row]; 
if (cell == nil) { 
    cell = [[WTHAITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
} 

// Display recipe in the table cell 
cell.nameLabel.text = [location valueForKey:@"name"]; 
cell.longLabel.text = [location valueForKey:@"longitude"]; 
cell.latLabel.text = [location valueForKey:@"latitude"]; 


return cell; 

} 

这是保存数据的代码。

- (IBAction)save:(id)sender { 

NSManagedObjectContext *context = [self managedObjectContext]; 
NSManagedObject *newLocation = [NSEntityDescription insertNewObjectForEntityForName:@"SavedLocations" inManagedObjectContext:context]; 
[newLocation setValue:self.LongLable.text forKey:@"longitude"]; 
[newLocation setValue:self.LatLable.text forKey:@"latitude"]; 
[newLocation setValue:self.name.text forKey:@"name"]; 

NSError *error = nil; 

if (![context save:&error]) { 

    NSLog(@"Can't Save! %@ %@", error, [error localizedDescription]); 

} 

[self dismissViewControllerAnimated:YES completion:nil]; 
} 

就像我说的,我得到正确数量的细胞,但都是空的。任何帮助将是伟大的!如果你需要任何额外的信息让我知道。

+1

你的自定义TableViewCell究竟是什么?它有xib吗?你检查了“位置”值吗? – Larme

+1

问题。你用xib设计了你的Cell吗?或者,以编程方式? – iphonic

+0

设计了使用故事板的细胞。 Larme-我如何检查除加载它们之外的值? – joffd

回答

0

PLZ试图改变线路

static NSString *CellIdentifier = @"customCell"; 

这里customCell意味着你通过小区标识在属性检查器中的故事板

给这可能会解决你的问题的名称。