【发布时间】:2011-06-19 18:54:58
【问题描述】:
我正在 Interface Builder 中使用 NavigationController 和 BandListViewController(UITableViewController) 创建一个简单的界面,并将委托设置为 AppDelegate 属性。
@interface CRUDAppDelegate : NSObject <UIApplicationDelegate> {
UINavigationController *bandNav;
BandListViewController *bandList;
}
和
但是,我不知道如何初始化 BandListViewController 并传递参数 managedObjectContext 而不将其设置在 awakeFromNib 上。 CRUDAppDelegate 已经初始化了这个控制器并将他自己的 nib 设置到 navigationController 中,但是当我尝试使用 initInManagedObjectContext 在 didFinishLaunchingWithOptions 中创建一个新的 BandListViewController 时,显示(TableViewController)仍然是旧的 bandList。 (使用 managedObjectContext = null)
到目前为止,我所做的是按照 Apple 的建议将 bandList managedObjectContext 保持在 awakeFromNib。
- (void)awakeFromNib
{
/*
Typically you should set up the Core Data stack here, usually by passing the managed object context to the first view controller.
self.<#View controller#>.managedObjectContext = self.managedObjectContext;
*/
self.bandList.managedObjectContext = self.managedObjectContext;
}
我想要什么
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.bandList = [[BandListViewController alloc] initInManagedObjectContext:self.managedObjectContext];
// Override point for customization after application launch.
[self.window addSubview:bandNav.view];
[self.window makeKeyAndVisible];
return YES;
}
【问题讨论】:
标签: iphone ios core-data interface-builder nsmanagedobjectcontext