根视图控制器?

时间:2011-07-25 22:59:23

标签: uiviewcontroller self uiwindow sharekit

我正在使用ShareKit,这是一个针对iOS应用的开源共享基础。有一个已知错误阻止Kit检测您的根视图控制器是什么。该错误的修复是在应用代理中添加[SHK setRootViewController:myViewController];

如果修补程序在UIApplication didFinishLaunching方法中,那么视图控制器不会只是self吗?我错过了什么?我也试过self.viewControllerself.window.rootViewControllerself.window无济于事。

编辑:以下是整个didFinishLoading

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.viewController = [[Chatter_BoxViewController alloc] initWithNibName:@"Chatter_BoxViewController" bundle:nil]; 
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    [SHK setRootViewController:self.viewController];

    return YES;
}

1 个答案:

答案 0 :(得分:2)

如果在didFinishLaunching中它只是“自我”,它会引用UIApplication,你不同意吗?你是否正确启动了viewController?发布更多代码。 :)

评论您的编辑:

如果您在XIB中正常设置了窗口,则不需要:

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

另外,如果你这样做(假设你的viewController被保留为属性):

self.viewController = [[Chatter_BoxViewController alloc] initWithNibName:@"Chatter_BoxViewController" bundle:nil]; 

你会有泄漏。就这样做:

viewController = [[Chatter_BoxViewController alloc] initWithNibName:@"Chatter_BoxViewController" bundle:nil];