Facebook のログインが成功したら、ViewControllers を使用して tabbarcontroller を追加する必要がありますが、方法がわかりませんか?
私は appDelegate.m に持っています:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
SearchView *first=[[SearchView alloc]
initWithNibName:@"SearchView" bundle:nil];
Login *second=[[Login alloc]initWithNibName:@"Login" bundle:nil];
second.title=@"Login";
NSArray *viewArray=[[NSArray alloc] initWithObjects: first,second,nil];
tabBarController=[[UITabBarController alloc] init];
[tabBarController setViewControllers:viewArray animated:NO];
[self.window addSubview:tabBarController.view];
[self.window makeKeyAndVisible];
[viewArray release];
[first release];
[second release];
return YES;
}
}
- (void)sessionStateChanged:(FBSession *)session
state:(FBSessionState) state
error:(NSError *)error
{
switch (state) {
case FBSessionStateOpen:
if (!error) {
FBLogin *fblogin=[[FBLogin alloc]initWithNibName:@"FBLogin" bundle:nil];
[self.window addSubview:fblogin.view];
}
break;
case FBSessionStateClosed:
case FBSessionStateClosedLoginFailed:
[[FBSession activeSession] closeAndClearTokenInformation];
break;
default:
break;
}
[[NSNotificationCenter defaultCenter]
postNotificationName:FBSessionStateChangedNotification
object:session];
if (error) {
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:@"Error"
message:error.localizedDescription
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
}
}
In FBLogin.m :
-(void)viewDidAppear:(BOOL)animated
{
SearchView *searchViewController=[[SearchView alloc]initWithNibName:@"SearchView" bundle:nil];
UserProfile *userprofile=[[UserProfile alloc]initWithNibName:@"UserProfile" bundle:nil];
userprofile.title=@"My Profile";
LogOut *logout=[[LogOut alloc]initWithNibName:@"LogOut" bundle:nil];
logout.title=@"Sign Out";
tab=[[UITabBarController alloc]init];
tab.viewControllers=[NSArray arrayWithObjects:searchViewController,userprofile,logout, nil];
[self presentModalViewController:tab animated:NO];
}
しかし、fBLogin に追加された tabbarcontroller を確認できませんでした。空の白いビューが表示されます。
そうですか。どうすれば達成できますか?