[英]tableView cellForRowAtIndexPath: runs before ViewDidLoad?
[英]NSObject changing property value between ViewDidLoad and cellForRowAtIndexPath
我通過prepareForSegue的方式將NSManagedObject傳遞給視圖控制器。
我要分配給的對象在接收ViewController中這樣聲明:
@property (retain, nonatomic) Allowance *allowanceSchedule;
所述對象具有稱為類型的屬性,其為NSNumber。 當我將對象傳遞給接收ViewController時,該屬性在發送ViewController中設置為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;
}
}
我的猜測是您的對象在某處出現故障,或者您的manageObjectContext正在失效。 CoreData將向控制台輸出調試消息,再次檢查它,看看是否有任何打印內容。
檢查是否在另一個線程上使用了該對象,或者是否意外地進行了回滾。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.