神奇记录:如何获取 NSDate 实体属性并将其显示到 UITableViewCell 中的 UILabel?

Magical Record: How to fetch and display an NSDate entity attribute to a UILabel in a UITableViewCell?

我正在使用 MagicalRecord 在 Core Data 实体的属性中存储日期和描述列表,我需要将它们显示到 UITableViewCell 中的 UILabel。但是每当我访问 UITableViewController 时,我的应用程序就会崩溃。我不确定它为什么会崩溃,但我相信这是因为 NSDate 对象。请帮忙。

时间+CoreDataProperties.h

#import "Time.h"

NS_ASSUME_NONNULL_BEGIN

@interface Time (CoreDataProperties)

@property (nullable, nonatomic, retain) NSString *title;
@property (nullable, nonatomic, retain) TimeDetails *timeDetails;

@end

NS_ASSUME_NONNULL_END

UITableViewController

-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
    [self configureCell:cell atIndex:indexPath];
    return cell;
}

-(void) configureCell: (UITableViewCell *) cell atIndex:(NSIndexPath *) indexPath
{
    Time *time = self.times[indexPath.row];
    UILabel *titleLabel = (UILabel *) [cell viewWithTag:100];
    titleLabel.text = time.title;

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateStyle:NSDateFormatterMediumStyle];
    NSString *dateDetails = [dateFormatter stringFromDate:time.timeDetails.date];
    NSLog(@"Date is %@",dateDetails);
    UILabel *dateLabel = (UILabel *) [cell viewWithTag:101];
    dateLabel.text = dateDetails;
}

错误信息:- 由于未捕获的异常 'NSUnknownKeyException' 而终止应用程序,原因:'[setValue:forUndefinedKey:]:此 class 与键 dateLabel2 的键值编码不兼容。'

无论您在故事板或 XIB 中的何处定义单元格,您都已将出口连接到标签,但该出口不存在。出口名为 dateLabel2.

仔细检查电池中的所有标签,检查它们的插座连接并移除任何无效的。