根视图控制器?
我正在使用 ShareKit
,这是一个 iOS 应用程序的开源共享基础。有一个已知的错误会阻止该套件检测您的根视图控制器是什么。该错误的修复方法是在应用程序委托中添加 [SHK setRootViewController:myViewController];
。
如果修复是在 UIApplication didFinishLaunching
方法中,那么视图控制器不就是 self
吗?我缺少什么?我还尝试过 self.viewController 、 self.window.rootViewController 和 self.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;
}
I'm working with ShareKit
, an open-source sharing foundation for iOS apps. There is a known bug that prevents the Kit from detecting what your root view controller is. The fix for that bug is adding [SHK setRootViewController:myViewController];
in the app delegate.
If the fix is in the UIApplication didFinishLaunching
method, wouldn't the view controller just be self
? What am I missing? I've also tried self.viewController
, self.window.rootViewController
and self.window
to no avail.
EDIT: Here's the entire 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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果 didFinishLaunching 中它只是“self”,它将引用 UIApplication,您不同意吗?您是否正确初始化了 viewController?发布更多代码。 :)
对您的编辑进行评论:
如果您在 XIB 中正常设置了窗口,则不需要这样做:
另外,如果您这样做(假设您的 viewController 被保留为属性):
您将会遇到泄漏。只需这样做:
If it would only be "self" in the didFinishLaunching it would refer to the UIApplication, don't you agree? Are you initing correctly the viewController? Post some more code. :)
Comment to your Edit:
If you have your Window set normally in your XIB you don't need this:
Also, if you do this (presuming your viewController is retained as property):
You will have a leak. Just do this: