开发者

iPhone: transfer objects between NSManagedObjectContext objects?

I currently have an NSManagedObjectContext containing 5 Video Objects displayed in a table view.

When a user selects a row, I'm going to push in a new view controller to display object details, and give the user the option to 'add Video to favorites'.

To do this, I want to create a new NSManagedObj开发者_JAVA百科ectContext, assign the selected Video to it, and push it to the new view controller.

Can someone please explain how I can do this?

My existing code looks something like:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    VideoDetails *vd = [[VideoDetails alloc] initWithStyle:UITableViewStyleGrouped];
    vd.video = [videoArray objectAtIndex:indexPath.row];

    [[self navigationController] pushViewController:vd animated:YES];

}


Why are you intent on creating a new NSManageObjectContext? Although contexts are relatively cheap, as long as you will not be accessing a context on multiple threads, it's much easier to just use one context and pass a reference to it to the new controller.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜