【问题标题】:Application windows are expected to have a root view controller at the end of application launch应用程序窗口应该在应用程序启动结束时有一个根视图控制器
【发布时间】:2012-04-08 08:00:00
【问题描述】:

我正在使用facebook iOS SDK设置教程:https://developers.facebook.com/docs/mobile/ios/build/

在第 4 步:将注销添加到您的应用之后,

我在 5.1 模拟器(xcode 4.3.2)上看到一个空白屏幕,并且控制台显示一条消息:

应用程序窗口在应用程序启动结束时应该有一个根视图控制器

EDIT-1

感谢您的回复; 我在创建应用程序时选择了“单一视图应用程序”模板。在 MainStoryBoard.storyboard 中,我创建了一个对象并将 MyGreatIOSAppAppDelegate 类分配给它。将此对象的 viewController 出口拖放到视图控制器。

这是 MyGreatIOSAppAppDelegate.m 中的代码

#import "MyGreatIOSAppAppDelegate.h"
#import "xxxViewController.h"

@implementation IJSAppDelegate

@synthesize window = _window;
@synthesize viewController = _viewController;
@synthesize facebook;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];

    // Add the logout button
    UIButton *logoutButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    logoutButton.frame = CGRectMake(40, 40, 200, 40);
    [logoutButton setTitle:@"Log Out" forState:UIControlStateNormal];
    [logoutButton addTarget:self action:@selector(logoutButtonClicked)
           forControlEvents:UIControlEventTouchUpInside];
    [self.viewController.view addSubview:logoutButton];    

    facebook = [[Facebook alloc] initWithAppId:@"id" andDelegate:self];

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    if ([defaults objectForKey:@"FBAccessTokenKey"] 
        && [defaults objectForKey:@"FBExpirationDateKey"]) {
        facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
        facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
    }
    if (![facebook isSessionValid]) {
        [facebook authorize:nil];
    }
    return YES;
}


- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    return [facebook handleOpenURL:url]; 
}

- (void)fbDidLogin {
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"];
    [defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"];
    [defaults synchronize];
}

// Method that gets called when the logout button is pressed
- (void) logoutButtonClicked:(id)sender {
    [facebook logout];
}

- (void) fbDidLogout {
    // Remove saved authorization information if it exists
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    if ([defaults objectForKey:@"FBAccessTokenKey"]) {
        [defaults removeObjectForKey:@"FBAccessTokenKey"];
        [defaults removeObjectForKey:@"FBExpirationDateKey"];
        [defaults synchronize];
    }
}

@end

【问题讨论】:

标签: iphone ios facebook


【解决方案1】:

检查您的应用程序委托的 application:didFinishLaunchingWithOptions: 方法中是否包含以下行:

self.window.rootViewController = self.viewController;

【讨论】:

  • 嗨@jonkroll,我正在使用 self.window.rootViewController = self.viewController;我不确定,但我在 MainStoryboard.storyboard 中遗漏了一些东西,我创建了一个对象并将 MyGreatIOSAppAppDelegate 类分配给它。将此对象的 viewController 出口拖放到视图控制器。
【解决方案2】:

确保您将 window.rootviewcontroller 设置为您的 _navigationviewcontroller。像这样:(这一切都发生在您的 AppDelegate.cs 文件中)

公共部分类 AppDelegate : UIApplicationDelegate { // 类级声明 UIWindow _window; UINavigationController _navigationcontroller;

    //
    // This method is invoked when the application has loaded and is ready to run. In this 
    // method you should instantiate the window, load the UI into it and then make the window
    // visible.
    //
    // You have 17 seconds to return from this method, or iOS will terminate your application.
    //

    public override bool FinishedLaunching (UIApplication app, NSDictionary options)
    {
        // create a new window instance based on the screen size
        _window = new UIWindow (UIScreen.MainScreen.Bounds);

        // If you have defined a view, add it here:
        // window.AddSubview (navigationController.View);
        _navigationcontroller = new UINavigationController();
        _navigationcontroller.PushViewController(new SplashViewController(),false);
        **_window.RootViewController = _navigationcontroller;**

        // make the window visible



    _window.MakeKeyAndVisible ();

        return true;
    }
}

}

【讨论】:

  • jqueryEnthusiast,您的查询得到最终解决方案了吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-23
  • 1970-01-01
  • 1970-01-01
  • 2015-12-16
相关资源
最近更新 更多