2014-07-23 6 views
0

prepareForSegue를 통해 NSManagedObject를 뷰 컨트롤러에 전달합니다. NSObject는 ViewDidLoad와 cellForRowAtIndexPath 사이의 속성 값을 변경합니다.

개체

가 나는 등의 ViewController받는 선언을 할당하고 있습니다 :

@property (retain, nonatomic) Allowance *allowanceSchedule; 

말했다 오브젝트가의 NSNumber이다라는 속성 유형이 있습니다. 받는 viewcontroller 개체를 전달할 때이 속성은 보내는 viewcontroller 1로 설정됩니다.

수신 컨트롤러에서 ViewDidLoad에서이 속성이 실제로 1로 설정되어 있지만 cellForRowAtIndexPath에서 속성이 0 (해당 코어 데이터 기본값)으로 설정되어 있는지 확인할 수 있습니다. 코드의 다른 지점에서이 속성을 설정했습니다. 어떤 도움을 주셔서 감사합니다. '

- (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

확률이 높으면 컨테이너가 0 일 것입니다. –

답변

2

내 생각 엔 당신의 목적은 당신에게 어딘가에 장애가 발생하거나지고 있는지 : prepareForSegue

- (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; 

}

그리고 여기 : 여기

은 cellForRowAtIndexPath 코드입니다 manageObjectContext가 무효화되고 있습니다. CoreData는 콘솔에 디버그 메시지를 뱉어 내고, 다시 점검하고, 인쇄 중인지 확인합니다.

다른 스레드에서 개체를 사용하고 있는지 또는 실수로 롤백을했는지 확인하십시오.

관련 문제