Core data 神奇记录:如何在UITableViewCell中获取并显示UILabel的NSDate实体属性?

Core data 神奇记录:如何在UITableViewCell中获取并显示UILabel的NSDate实体属性?,core-data,nsdate,magicalrecord,Core Data,Nsdate,Magicalrecord,我正在使用MagicalRecord在核心数据实体的属性中存储日期和描述的列表,我需要将它们显示在UITableViewCell中的UILabel中。但每当我访问UITableViewController时,我的应用程序就会崩溃。我不确定它为什么会崩溃,但我相信这是因为NSDate对象。请帮忙 时间+CoreDataProperties.h #import "Time.h" NS_ASSUME_NONNULL_BEGIN @interface Time (CoreDataProperties

我正在使用MagicalRecord在核心数据实体的属性中存储日期和描述的列表,我需要将它们显示在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:]:此类不符合key dateLabel2的键值编码要求。”

无论您在故事板或XIB中定义了单元格,您都已将插座连接到标签,但该插座不存在。该插座称为
dateLabel2


检查单元格中的所有标签,检查其上的插座连接并删除任何无效的。

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


检查单元格中的所有标签,检查其上的插座连接,并删除任何无效的标签。

是否尝试使用调试器?你能确定你的程序在哪一行崩溃吗?它在这里崩溃:-UITableViewCell*cell=[tableView dequeueReusableCellWithIdentifier:@“cell”forIndexPath:indexPath];您需要在
[self.tableView registerClass:[UITableViewCell class]forCellReuseIdentifier:@“cell”中使用
tableView
注册单元格您可以将这一行放入
viewDidLoad
感谢简单的代码,这确实可以解决崩溃问题。但是,我的UITableViewController为空。它没有在时间实体中显示属性。您需要为
-(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)节添加一个实现
您尝试过使用调试器吗?你能确定你的程序在哪一行崩溃吗?它在这里崩溃:-UITableViewCell*cell=[tableView dequeueReusableCellWithIdentifier:@“cell”forIndexPath:indexPath];您需要在
[self.tableView registerClass:[UITableViewCell class]forCellReuseIdentifier:@“cell”中使用
tableView
注册单元格您可以将这一行放入
viewDidLoad
感谢简单的代码,这确实可以解决崩溃问题。但是,我的UITableViewController为空。它没有显示时间实体中的属性。您需要为
-(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)节添加一个实现。我找到了outlet dateLabel2,随后将其删除。但我仍然无法显示我的属性。这是另一个问题。除非它仍然是一个未定义的关键例外嗨,韦恩,谢谢。我找到了outlet dateLabel2,随后将其删除。但我仍然无法显示我的属性。这是另一个问题。除非它仍然是一个未定义的密钥异常