我正在为我的应用程序(基本 SDK:iOS5)使用 Facebook SDK 3.0,并使用 Scrumptious 应用程序(示例应用程序)作为教程。如果 Facebook 没有打开会话,则会以模态方式呈现登录视图控制器。但它没有以模态方式呈现。这是代码;
- (void)showLoginView {
UIViewController *topViewController = [self.navigationController topViewController]; // not nil, RootViewController kind of class
UIViewController *modalViewController = [topViewController modalViewController]; // nil since not modalviewcontroller exists
if (![modalViewController isKindOfClass:[FacebookLoginViewController class]]) {
FacebookLoginViewController *loginViewController = [[FacebookLoginViewController alloc] initWithNibName:@"FacebookLoginViewController" bundle:nil]; // allocated, no problem
[topViewController presentModalViewController:loginViewController animated:NO]; // not working????
} else {
FacebookLoginViewController* loginViewController = (FacebookLoginViewController*)modalViewController;
[loginViewController loginFailed];
}
}
细节;
- showLoginView 被调用
application:didFinishLaunchingWithOptions:
并在分配了 navigationController 之后被调用 RootViewController
调用前导航控制器的调用viewDidLoad
方法showLoginView
- in
showLoginView
,topViewController
不是 nil (应该是RootViewController
:) - navigationController 是一种 UINavigationController 类(不是自定义的)
loginViewController
(FacebookLoginViewController
) 的init
方法被调用,但不是它的viewDidLoad
方法)
日志输出:
2013-03-21 20:01:28.729 RootViewController: viewDidLoad
2013-03-21 20:01:28.735 FacebookLoginViewController:已分配