一个视图控制器出现在iOS 5及更低版本的另一个视图控制器上

时间:2013-04-05 13:31:52

标签: iphone ipad xcode4.5

我有一个带有两个视图控制器的UItabbarController。当我单击一个视图控制器中的登录按钮时,它应该带我到其他tabbarController。当发生这种情况时,我将第一个视图控制器放在当前tabbarcontroller的顶部,它看起来像另一个。它在iPhone 6.0模拟器中工作正常,但是如iPhone 5.0模拟器中所描述的那样失败。

在appDelegate.m中:

     - (void)sessionStateChanged:(FBSession *)session
                  state:(FBSessionState) state
                  error:(NSError *)error
  {
    switch (state) {
    case FBSessionStateOpen:
        if (!error) {




            if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPhone)
            {
                FLogin *flogin=[[FLogin alloc]initWithNibName:@"FLogin" bundle:nil];

                self.window.rootViewController=fblogin;  // I think because of this I m getting this issue


            }



        }

}

在flogin.m

   tab=[[[UITabBarController alloc]init]autorelease];
          ViewController *searchViewController=[[[ViewController   alloc]initWithNibName:@"ViewController" bundle:nil]autorelease];
            Account *account=[[[Account alloc]initWithNibName:@"Account" bundle:nil]autorelease];
            account.title=@"My Account";



            tab.viewControllers=[NSArray arrayWithObjects:searchViewController,account,nil];
            for(UIViewController *tab1 in  tab.viewControllers)

            {
                if ([[[UIDevice currentDevice] systemVersion] floatValue]>5.0 ||[[[UIDevice currentDevice] systemVersion] floatValue]==5.0)
                {
                    [tab.tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                            [UIFont fontWithName:@"TimesNewRomanPS-BoldMT" size:16.0], UITextAttributeFont, nil]
                                                  forState:UIControlStateNormal];
                }
            }

            [self presentModalViewController:tab animated:NO];

1 个答案:

答案 0 :(得分:0)

您是说您只是想以编程方式切换标签以响应登录?如果是这样,您不应该使用presentModalViewController:。切换标签的正确方法是使用UITabBarController方法。

[self.tabBarController setSelectedIndex:1];

[self.tabBarController setSelectedViewController:self.myOtherViewController];