应用程序窗口预计在应用程序启动结束时具有根视图控制器 [英] Application windows are expected to have a root view controller at the end of application launch

查看:73
本文介绍了应用程序窗口预计在应用程序启动结束时具有根视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很喜欢iOS和Facebook开发...



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



在步骤4:添加注销到您的应用程序后,



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

 应用程序窗口预计在应用程序启动结束时具有根视图控制器

我错过了一个基本设置,有人可以指出...



感谢!



EDIT-1



感谢您的回复;
在创建应用程序时,我选择了单一查看应用程序模板。在MainStoryBoard.storyboard中,我创建了一个对象并为其分配了MyGreatIOSAppAppDelegate类。将此对象的viewController插槽拖放到View Controller。



这里是MyGreatIOSAppAppDelegate.m中的代码

  #importMyGreatIOSAppAppDelegate.h
#importxxxViewController.h

@implementation IJSAppDelegate

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

- (BOOL)应用程序:(UIApplication *)应用程序didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//在应用程序启动后重写自定义点。
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];

//添加注销按钮
UIButton * logoutButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
logoutButton.frame = CGRectMake(40,40,200,40);
[logoutButton setTitle:@Log OutforState:UIControlStateNormal];
[logoutButton addTarget:self action:@selector(logoutButtonClicked)
forControlEvents:UIControlEventTouchUpInside];
[self.viewController.view addSubview:logoutButton];

facebook = [[Facebook alloc] initWithAppId:@idandDelegate:self];

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



- (BOOL)应用程序:(UIApplication *)应用程序openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication注释:( id )注释{
return [facebook handleOpenURL:url];
}

- (void)fbDidLogin {
NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[facebook accessToken] forKey:@FBAccessTokenKey];
[defaults setObject:[facebook expirationDate] forKey:@FBExpirationDateKey];
[默认同步];

}

//当按下注销按钮时调用的方法
- (void)logoutButtonClicked:(id)sender {
[facebook登出];
}

- (void)fbDidLogout {
//如果存在,删除保存的授权信息
NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
if([defaults objectForKey:@FBAccessTokenKey]){
[defaults removeObjectForKey:@FBAccessTokenKey];
[defaults removeObjectForKey:@FBExpirationDateKey];
[默认同步];
}
}

- (void)applicationWillResignActive:(UIApplication *)应用程序
{
//当应用程序即将从活动中移动时发送到无效状态。某些类型的暂时中断(如来电或短信)或当用户退出应用程序并开始转换到背景状态时,可能会发生这种情况。
//使用此方法暂停正在进行的任务,禁用定时器,并降低OpenGL ES帧速率。游戏应该使用这种方法暂停游戏。
}

- (void)applicationDidEnterBackground:(UIApplication *)应用程序
{
//使用此方法释放共享资源,保存用户数据,使定时器无效,并存储足够的应用程序状态信息以将应用程序恢复到当前状态,以备稍后终止。
//如果您的应用程序支持后台执行,则调用此方法而不是applicationWillTerminate:当用户退出时。
}

- (void)applicationWillEnterForeground:(UIApplication *)应用程序
{
//被调用为从后台转换到非活动状态的一部分;在这里,您可以撤消进入后台的许多更改。
}

- (void)applicationDidBecomeActive :( UIApplication *)应用程序
{
//在应用程序中重新启动任何已暂停(或尚未启动)的任务没有活动如果应用程序以前是在后台,请选择刷新用户界面。
}

- (void)applicationWillTerminate :( UIApplication *)应用程序
{
//当应用程序即将终止时调用。酌情保存数据。另请参见applicationDidEnterBackground :.
}

@end


解决方案

检查您的应用程序委托的应用程序中是否具有以下一行:didFinishLaunchingWithOptions:方法:

  self.window.rootViewController = self.viewController; 


I am new to iOS and facebook development...

I am using the facebook iOS SDK setup tutorial: https://developers.facebook.com/docs/mobile/ios/build/

After Step 4: Adding Log Out to your App,

I get a blank white screen on the 5.1 simulator (xcode 4.3.2) and the console shows a message:

Application windows are expected to have a root view controller at the end of application launch

I am missing a basic setting, can someone point it...

Thanks!

EDIT-1

Thanks for your responses; I chose a "Single View Application" template while creating the app. In the MainStoryBoard.storyboard, I created an object and assigned the MyGreatIOSAppAppDelegate class to it. Drag-dropped the viewController outlet of this object to the View Controller.

here is the code in 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];
    }
}

- (void)applicationWillResignActive:(UIApplication *)application
{
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end

解决方案

Check that you have the following line in your application delegate's application:didFinishLaunchingWithOptions: method:

self.window.rootViewController = self.viewController;

这篇关于应用程序窗口预计在应用程序启动结束时具有根视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆