2012-03-23 35 views
2

我使用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代碼

#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 
+0

難道您發佈'MyGreatIOSAppAppDelegate.m'。你可以編輯這個帖子來做到這一點。 – Drew 2012-03-23 18:36:55

+0

你解決了這個問題嗎?如果你發佈瞭解決方案,我會遇到同樣的問題。 – Hosni 2012-06-04 12:42:35

+0

您使用的是哪個版本的Xcode?不同的版本有不同的項目模板。你可以發佈'main.c'和你的應用程序委託標題嗎?還有你的故事板和Info.plist中的對象列表? – Jim 2012-07-28 23:15:36

回答

6

檢查是否有下面的行應用程序委託的application:didFinishLaunchingWithOptions:方法:

self.window.rootViewController = self.viewController; 
+0

您好@jonkroll,我使用self.window.rootViewController = self.viewController; 我不確定,但我缺少MainStoryboard.storyboard中的某些東西,我創建了一個對象並將MyGreatIOSAppAppDelegate類分配給它。將此對象的viewController出口拖放到View Controller。 – jqueryEnthusiast 2012-03-23 21:27:20

0

確保您設置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; 
    } 
} 

}

+1

你可能不應該認爲大多數iOS開發人員正在使用Xamarin ... – 2014-02-15 21:16:16

+0

這是一個很好的建議Aaron V .. – mrMagik3805 2014-02-17 04:18:12

+0

jqueryEnthusiast,你有最終的解決方案,你的查詢? – mrMagik3805 2014-02-17 04:20:48

相關問題