1
我有一個登錄視圖控制器向服務器請求認證。一旦成功,我希望當前視圖控制器成爲我的應用程序的主頁選項卡視圖控制器。我曾嘗試使用pushViewController:viewController或presentModalViewController或dismissModalViewControllerAnimated。什麼都沒有您可以查看提供的截圖以瞭解我的應用程序流程。如何更改當前視圖控制器?
下面是一些示例代碼:
- (IBAction)facebookLoginButtonClick:(id)sender {
// get the app delegate so that we can access the session property
AppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];
// this button's job is to flip-flop the session from open to closed
if (appDelegate.session.isOpen) {
// if a user logs out explicitly, we delete any cached token information, and next
// time they run the applicaiton they will be presented with log in UX again; most
// users will simply close the app or switch away, without logging out; this will
// cause the implicit cached-token login to occur on next launch of the application
[appDelegate.session closeAndClearTokenInformation];
} else {
if (appDelegate.session.state != FBSessionStateCreated) {
// Create a new, logged out session.
appDelegate.session = [[FBSession alloc] init];
}
// if the session isn't open, let's open it now and present the login UX to the user
[appDelegate.session openWithCompletionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
// and here we make sure to update our UX according to the new session state
[self dismissModalViewControllerAnimated:YES];
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle: nil];
MainViewTabBarController *viewController = (MainViewTabBarController*)[mainStoryboard instantiateViewControllerWithIdentifier: @"mainPageTabBarId"];
[[self navigationController] presentModalViewController:viewController animated:YES];
}];
}
}
當你說它不起作用時,你的意思是按鈕完全沒有響應?你在做錯誤檢查嗎?記錄語句以查看完成塊是否返回有效的FBSession? – geraldWilliam
指向視圖控制器的2個箭頭的左側有沒有東西?它看起來像你有兩個控制器都設置爲初始控制器(這是不可能的,我不認爲)。 – rdelmar
按鈕響應。但應用程序崩潰。 – flashsnake