Я использую MagicalRecord для хранения списка дат и описаний в атрибуте объекта Core Data, и мне нужно отобразить их в UILabel в UITableViewCell. Но мое приложение падает, когда я обращаюсь к UITableViewController. Я не уверен, почему он сбой, но я считаю, что это из-за объекта NSDate. Пожалуйста помоги.Magical Record: Как получить и отобразить атрибут объекта NSDate для UILabel в UITableViewCell?
Время + 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]: это класс не является ключевым значением, совместимым с кодировкой для ключевого dateLabel2. '
Вы пытались использовать отладчик? Можно определить, на какой строке вы сработали? –
Это сбой здесь: - UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier: @ "Cell" forIndexPath: indexPath]; –
Вам нужно зарегистрировать ячейку с помощью 'tableView', как в' [self.tableView registerClass: [UITableViewCell class] forCellReuseIdentifier: @ "Cell"]; 'вы можете поместить эту строку в' viewDidLoad' –