2014-07-23 23 views
0

我通過prepareForSegue的方式將NSManagedObject傳遞給視圖控制器。NSObject更改ViewDidLoad和cellForRowAtIndexPath之間的屬性值

目的我分配給在ViewController中作爲這樣的接收宣稱:

@property (retain, nonatomic) Allowance *allowanceSchedule; 

。所述對象具有屬性稱爲類型,是一個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; 
} 

}

+2

請顯示您的代碼 - 'cellForRowAtIndexPath'作爲最低 – Paulw11

+0

我已經使用代碼編輯過。謝謝。 – Rod

+0

賠率非常好,價值爲零,因爲據稱容器的容器是零。 –

回答

2

我的猜測是,你的目標是越來越故障的地方,或者你」重新manageObjectContext正在失效。 CoreData會將調試消息吐出到控制檯,仔細檢查並看看是否有任何正在打印的東西。

檢查是否在不同線程上使用該對象,或意外進行回滾。