0

3ページのアプリケーションを作成しています

  1. ログインページ - アプリがロードされた後の最初のページ
  2. My First Page - ユーザーが正常にログインすると、このページが表示されます。このページ
    には、2 つの UITabBarItem を持つ UITabBar が含まれています。最初のものはに接続されています

    私の最初のページ

    もう 1 つは My Second Page です。

  3. My Second Page - これは別の UIViewController です。

ログインページを作成しましたが、最初のページに UITabBar を追加するための解決策が見つかりません

私を助けてください

4

4 に答える 4

0

Interface Builderを使用していますか?私の観点からは、プログラムによる実装方法を使用したいと思います。

//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

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

ログインが成功したことを確認できる場所に Tabbar を作成する必要があります。このメソッドは、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 に答える
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 に答える