Ios 从核心数据分配的变量变为空
在我的应用程序中,我正在实现核心数据。执行fetch之后,我将fetch数据用作表视图的数据源 我不太熟悉将NSFetchedResultsController集成为表数据源,因此我的做法有所不同Ios 从核心数据分配的变量变为空,ios,uitableview,core-data,segue,Ios,Uitableview,Core Data,Segue,在我的应用程序中,我正在实现核心数据。执行fetch之后,我将fetch数据用作表视图的数据源 我不太熟悉将NSFetchedResultsController集成为表数据源,因此我的做法有所不同 dataSourceItems = [[NSMutableArray alloc]initWithArray:[[myCoreData fetchedResultsController] fetchedObjects]]; NSLogging数据源项会返回获取的结果,因此直到现在它还可以正常工作。我
dataSourceItems = [[NSMutableArray alloc]initWithArray:[[myCoreData fetchedResultsController] fetchedObjects]];
NSLogging数据源项会返回获取的结果,因此直到现在它还可以正常工作。我使用它作为tableView数据源,我的单元格中充满了它的数据
点击单元格后,我正在推另一个项目详细视图控制器。我需要传递项目id,以便可以从核心数据执行另一次提取
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
MainItemListCell *cell = [_tblViewitems cellForRowAtIndexPath:indexPath];
NSLog(@"%@",cell.itemId);
ItemDetailsViewController *itemDetail = [[ItemDetailsViewController alloc]
initWithNibName:@"ItemDetailsViewController"
bundle:nil];
itemDetail.passedName = [NSString stringWithFormat:@"%@",cell.lblItemName.text];
itemDetail.passedValue = cell.lblAmount.text;
itemDetail.passedEvent =[dataSourceItems objectAtIndex:indexPath.row];
NSLog(@"Assigning %@",((MyCoreDataItem *)[dataSourceItems objectAtIndex:indexPath.row]).cEventId);
itemDetail.passedId = ((MyCoreDataItem *)[dataSourceItems objectAtIndex:indexPath.row]).cEventId;
itemDetail.passedStatus = cell.lblOweStatus.text;
[self.navigationController pushViewController:itemDetail animated:YES];
}
从我的牢房里出来
在NSLogging itemdail.passedId之后,我得到null
我还尝试了以下方法:
itemDetail.passedId = ((ItemDetail *)[dataSourceItems objectAtIndex:indexPath.row]).cEventId;
NSLog(@"Assigning %@",((ItemDetail *)[dataSourceItems objectAtIndex:indexPath.row]).cEventId);
Assigning (null)
Printing description of dataSourceItems:
<__NSArrayM 0x176815e0>(
<ItemDetail: 0x176828a0> (entity: ItemDetail; id: 0x17681870 <x-coredata://7E065CF5-7AC9-4BBB-A3F9-05DC5B155F60/ItemDetail/p1> ; data: <fault>)
)
n记录数据源项将返回以下结果:
itemDetail.passedId = ((ItemDetail *)[dataSourceItems objectAtIndex:indexPath.row]).cEventId;
NSLog(@"Assigning %@",((ItemDetail *)[dataSourceItems objectAtIndex:indexPath.row]).cEventId);
Assigning (null)
Printing description of dataSourceItems:
<__NSArrayM 0x176815e0>(
<ItemDetail: 0x176828a0> (entity: ItemDetail; id: 0x17681870 <x-coredata://7E065CF5-7AC9-4BBB-A3F9-05DC5B155F60/ItemDetail/p1> ; data: <fault>)
)
起初我认为数据:错误意味着错误。然而,我认为错误不是错误
然而,我真的不明白为什么我不能将核心数据值传递给我的细节VC。您必须首先创建核心数据实体,然后将其相关属性分配给相关ItemDetailsViewController的对象属性,如下所示
MyCoreDataItem *myCoreDataItem = (MyCoreDataItem *)[dataSourceItems objectAtIndex:indexPath.row];
itemDetail.passedId = myCoreDataItem.itemId;
注:-
您必须创建一个继承名为MyCoreDataItem的NSManagedObject的类,该类表示核心数据实体。你必须声明属性,比如itemId和你想要的其他东西 您确定dataSourceItems有数据吗?即使有,我的表视图也会填充数据。。。所以我认为,它确实可以保留FRC执行获取的NSManagedObjectContext吗?记录您的.managedObjectContextWell,我还尝试将属性MyCoreDataItem(NSManagedObject子类)添加到我的itemDetailsVC,然后像您在回答中那样分配它。。但仍然是nullitemDetail.passedItem=[dataSourceBundles objectAtIndex:indexath.row];NSLog@EVENT%@,itemdail.passedItem.cTitle;返回null passedItem is NSManagedObject子类