2012-07-09 87 views
1

我目前正在嘗試Facebook的單點登錄功能,在我的移動應用程序。到目前爲止,當我測試我的應用程序時,我可以訪問Facebook身份驗證對話框。但是當我點擊確定按鈕時,我的視圖給了我一個黑屏。我想知道這是否是因爲rootViewController的分配。相當奇怪的警告

enter image description here

在這行代碼在我FbSSOTrialDelegate.m

self.window.rootViewController = self.FbSSOTrialVC;

我得到一個警告說Incompatible pointer types assigning to 'UIViewController *' from 'FbSSOTrialViewController *'也該日誌在我的控制檯:

2012-07-09 11:17:04.798 FbSSOTrial[976:f803] Application windows are expected to have a root view controller at the end of application launch

我說這很奇怪,因爲我確定那FbSSOTrialVCUIViewController的子類

請問爲什麼會發生這種情況。下面分別對FbSSOTrialViewController.h

#import <UIKit/UIKit.h> 

@interface FbSSOTrialViewController : UIViewController 

@end 

和的appDelegate

FbSSOTrialDelegate.h

#import <UIKit/UIKit.h> 
#import "FBConnect.h" 

@class FbSSOTrialViewController; 


@interface FbSSOTrialAppDelegate : NSObject <UIApplicationDelegate, FBSessionDelegate> 
{ 
    Facebook *facebook; 
} 

@property (nonatomic, retain) IBOutlet UIWindow *window; 
@property (nonatomic, retain) IBOutlet FbSSOTrialViewController *FbSSOTrialVC; 
@property (nonatomic, retain) Facebook *facebook; 

@end 

FbSSOTrialDelegate.m

#import "FbSSOTrialAppDelegate.h" 

@implementation FbSSOTrialAppDelegate 

@synthesize window = _window; 
@synthesize facebook = _facebook; 
@synthesize FbSSOTrialVC = _FbSSOTrialVC; 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    // Override point for customization after application launch. 
    NSString *FbAppId = @"MY_APP_ID"; 

    self.window.rootViewController = self.FbSSOTrialVC; 
    [self.window makeKeyAndVisible]; 

    self.facebook = [[Facebook alloc] initWithAppId:FbAppId andDelegate:self]; 

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 

    if ([defaults objectForKey:@"FBAccessTokenKey"] && [defaults objectForKey:@"FBExpirationDateKey"]) { 
     self.facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"]; 
     self.facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"]; 
    } 

    if (![self.facebook isSessionValid]) { 
     [self.facebook authorize:nil]; 
    } 

    return YES; 
} 
+0

你確定'FbSSOTrialViewController * *實際*擴展了UIViewController嗎? – 2012-07-09 03:47:01

+0

是的,請參閱編輯。 – Grauzten 2012-07-09 04:02:30

+0

好吧,接下來是一個挑剔的細節,可能會流光。請注意星號...在錯誤消息中,它可疑地從FbSSOTrialViewController丟失:'從FbSSOTrialViewController'分配給'UIViewController *'。我想知道是否這是一個錯誤在SO上,或者如果確實沒有一個實際的指針,你認爲它存在(那*是*錯誤是什麼)......那麼接下來要問怎麼'self.FbSSOTrialVC '正在初始化。我懷疑你的問題在哪裏。它看起來像被設置爲Class對象,而不是指向實例的指針。 – 2012-07-09 04:07:25

回答

0

從我們的討論其他的代碼,它決定視圖控制器在應用程序啓動期間未正確實例化。我們確定,感興趣的視圖控制器是由一個故事板來了,所以建議代碼變化如下:

// remove this 
// self.window.rootViewController = self.FbSSOTrialVC; 

// and replace it with: 
self.FbSSOTrialVC = [self.window.rootViewController.storyboard instantiateViewControllerWithIdentifier:@"Fb SSO Trial VC"]; 
self.window.rootViewController = self.FbSSOTrialVC; 

注意,這需要你在故事板,感興趣的ViewController應該有標識「FB SSO試用VC「(根據需要更改)。