根视图控制器?

发布于 2024-11-25 22:46:04 字数 983 浏览 2 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小草泠泠 2024-12-02 22:46:04

如果 didFinishLaunching 中它只是“self”,它将引用 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]; 

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:

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

Also, if you do this (presuming your viewController is retained as property):

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

You will have a leak. Just do this:

viewController = [[Chatter_BoxViewController alloc] initWithNibName:@"Chatter_BoxViewController" bundle:nil]; 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文