0

我正在制作一个有 3 页的应用程序

  1. 登录页面 - 应用加载后的第一页
  2. 我的第一页- 当用户成功登录时,他会进入这个页面。这个页面
    包含一个带有两个 UITabBarItems 的 UITabBar。第一个连接到

    我的第一页

    另一个是我的第二页。

  3. 我的第二页- 这是另一个 UIViewController。

我已经创建了登录页面,但我无法在我的第一页中找到添加 UITabBar 的解决方案

请帮帮我

4

4 回答 4

0

试试这个,

假设这是 LoginViewController.m

-(IBAction)loginButtonClicked:(id)sender
{
    [self createTabBarView];
}

//Create TabBar View here 
-(void)createTabBarView
{
     NSMutableArray *tabItems = [NSMutableArray array];
     UIViewController *firstViewController = [[FirstViewController alloc] init];;
     firstViewController = @"First View";
     firstViewController = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemContacts tag:0];
      [tabItems addObject:firstViewController];
      UIViewController *secondViewController = [[SecondViewController alloc] init];;
      secondViewController = @"Second View";
      secondViewController = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemContacts tag:1];
      [tabItems addObject:secondViewController];
      self.tabBarController = [[UITabBarController alloc]init];
      self.tabBarController.viewControllers = tabItems;    
      self.tabBarController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
      [self presentModalViewController:tabBarController animated:YES];
}

谢谢,

尼基尔。

于 2012-07-18T06:35:32.810 回答
0

定义 AppDelegate.h

@property (strong, nonatomic) UITabBarController *tabBarController;

在 AppDelegate.m

didFinishLaunchingWithOptions

self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.delegate=self;
self.tabBarController.selectedIndex=0;
self.tabBarController.delegate=self;


 - (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{

return YES;
}

现在,当您成功登录时,在该方法中编写以下代码

    AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    UIViewController *viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
    UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];

    delegate.tabBarController = [[UITabBarController alloc] init];
    delegate.tabBarController.selectedIndex = 0;
    delegate.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, nil];
    delegate.tabBarController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    [self.navigationController pushViewController:delegate.tabBarController animated:YES];
于 2012-07-18T06:42:10.503 回答
0

你在使用界面生成器吗?从我的角度来看,我宁愿使用编程方式来实现它。

//In the appDidFinishLaunch method

    BOOL loggedIn = [[NSUserDefault standDefault]boolForKey:"userlogin"];

    if(loggedIn)
    {

        //Setup your UITabbarViewController

    }
    else
    {

        //Setup your loginView Controller
    }

登录 LogInViewController 后

- (void)didLogin
{

   YourAppDelegate *delegate = [UIApplication shareApplication].delegate;  

   [delegate.window addSubView:self.tabBarViewController.view];

   [delegate.window removeSubView:self.view]

   //Other Config

}
于 2012-07-18T06:47:42.723 回答
0

您应该在可以识别登录已成功完成的地方创建标签栏。这个方法应该是你 loginViewController 的一部分。创建一个像下面这样的函数来创建一个 Tabbar 并将其呈现在 loginController 上。

-(void) createTabBarController
{
     UITabBarController *tabBar = [[UITabBarController alloc]init];

     UIViewController *firstViewController = [[[UIViewController alloc] init]autorelease];
     UINavigationController *firstNavController = [[UINavigationController alloc]initWithRootViewController:firstViewController];
     firstNavController.tabBarItem.title=@"First Controller";
     firstNavController.tabBarItem.image = [UIImage imageNamed:@"first.png"];

     UIViewController *secondViewController = [[[UIViewController alloc] init]autorelease];
     UINavigationController *secondNavController = [[UINavigationController alloc]initWithRootViewController:secondViewController];
     secondNavController.tabBarItem.title=@"First Controller";
     secondNavController.tabBarItem.image = [UIImage imageNamed:@"first.png"];

     [tabBar setViewControllers:[NSArray arrayWithObject:firstNavController,secondNavController,nil]];    
     [firstNavController release];
     [secondNavController release];

     [self presentModalViewController: tabBar];
     [tabBar release];
}
于 2012-07-18T07:04:07.917 回答