【发布时间】:2014-07-24 07:19:12
【问题描述】:
我通过 prepareForSegue 将 NSManagedObject 传递给视图控制器。
我要分配的对象在接收视图控制器中声明如下:
@property (retain, nonatomic) Allowance *allowanceSchedule;
所述对象有一个名为 type 的属性,它是一个 NSNumber。 当我将对象传递给接收视图控制器时,该属性在发送视图控制器中设置为 1。
在接收控制器的 ViewDidLoad 中,我可以确认该属性确实设置为 1,但在 cellForRowAtIndexPath 中该属性设置为 0(其 coredata 默认值)。 在代码中没有其他地方我设置了这个属性。任何帮助表示赞赏。
这是 cellForRowAtIndexPath 代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [super tableView:tableView cellForRowAtIndexPath:indexPath];
if (indexPath.section == 0) { // Allowance type
if (indexPath.row == [self.allowanceSchedule.type integerValue])
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else
{
cell.accessoryType = UITableViewCellAccessoryNone;
}
}
if (indexPath.section == 1) { // Week starts on
cell.detailTextLabel.text = [Time weekStartDescriptionFromIndex:[self.allowanceSchedule.weekStart integerValue]];
}
return cell;
}
这是 prepareForSegue:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqual: @"allowance"]) {
AllowanceSetupTableViewController *allowanceViewController = (AllowanceSetupTableViewController *)segue.destinationViewController;
allowanceViewController.delegate = self;
if (self.child.allowanceSchedule == nil) {
self.child.allowanceSchedule = [NSEntityDescription insertNewObjectForEntityForName:@"Allowance" inManagedObjectContext:self.managedObjectContext];
}
allowanceViewController.allowanceSchedule = self.child.allowanceSchedule;
}
}
【问题讨论】:
-
请至少出示您的代码 -
cellForRowAtIndexPath -
我已经用代码进行了编辑。谢谢。
-
该值为零的可能性非常好,因为据说持有它的容器为零。
-
值在哪里设置为1?
-
是的,您正在分配一个新的核心数据对象并将其传递给您的视图控制器。我希望它为 0,因为您尚未将任何其他数据初始化到其中
标签: ios objective-c core-data