【发布时间】:2014-03-14 21:57:51
【问题描述】:
我想用这段代码在我的 TableView 中显示 CoreData:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Configure the cell...
NSManagedObject *device = [self.inventory objectAtIndex:indexPath.row];
[cell.textLabel setText:[NSString stringWithFormat:@"%@", [device valueForKey:@"InventoryProductName"]]];
[cell.detailTextLabel setText:[device valueForKey:@"expireDate"]];
return cell;
}
应用程序当然会崩溃,因为 expireDate 是一个日期而不是字符串/文本。 如何在 TableView 单元格的副标题中显示我的内容的过期日期?
【问题讨论】:
-
使用 NSDateFormatter
标签: uitableview core-data nsdate