0

Xcode 4.5で異なるタブビューにリンクされたルートビューコントローラーで複数のボタンを使用する方法は何ですか?

ホーム画面に4つのボタンがあります。ボタン1をタップするとタブ1に移動し、ボタン2をタップするとタブ2が開くようにフローが進みます。

私は何をすべきか?

ダミーコード これは無視してください。

{
   tabBarController.viewControllers = controllers;
    window.rootViewController = tabBarController;

}
4

3 に答える 3

0
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{
 UIViewController *viewController1 = [[[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil] autorelease]; 
    UIViewController *viewController2 = [[[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil] autorelease]; 
    UIViewController *viewController3 = [[[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil] autorelease]; 
    UIViewController *viewController4 = [[[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil] autorelease]; 
    self.tabBarController = [[[UITabBarController alloc] init] autorelease]; self.tabBarController.viewControllers = @[viewController1, viewController2,viewController3,viewController4]; 
    self.window.rootViewController = self.tabBarController;
}

このようなタブバーコントローラーを作成します

以下のような AppDelegate オブジェクトで上記のメソッドを呼び出します...

例: メソッドでその時点でクリックされた button1 は、次のコードを記述します...

- (IBAction)btn1_Clicked:(id)sender{
    AppDelegate *objApp = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    objApp.tabbarcontroller.selectedindex = 2;
}

selectedIndex を変更できます

于 2013-07-10T09:49:01.873 に答える
0

4 つの viewController を作成し、アプリのデリゲート メソッドに以下のコードを追加するだけです

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    UIViewController *viewController1 = [[[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil] autorelease];
    UIViewController *viewController2 = [[[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil] autorelease];
    UIViewController *viewController3 = [[[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil] autorelease];
    UIViewController *viewController4 = [[[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil] autorelease];
    self.tabBarController = [[[UITabBarController alloc] init] autorelease];
    self.tabBarController.viewControllers = @[viewController1, viewController2,viewController3,viewController4];
    self.window.rootViewController = self.tabBarController;
于 2013-07-10T09:03:22.517 に答える
0

あなたは怒鳴るようにそれを行うことができます..

UITabBarController最初にAppDelegateクラス内のオブジェクトを作成し、次のapplicationDidFinishLaunching:ようにメソッドに割り当てます..

self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController2 = [[[UITabBarController alloc]init]autorelease];
self.tabBarController3 = [[[UITabBarController alloc]init]autorelease];

以下のように別のタブを RootViewController として設定するためのメソッドを作成した後...

-(void)setRootViewControllerTab1{

    UIViewController *viewController1, *viewController2;
    UINavigationController *navviewController1 , *navviewController2,;

    viewController1 = [[[HomeViewController alloc] initWithNibName:@"viewController1" bundle:nil] autorelease];
    navviewController1=[[UINavigationController alloc]initWithRootViewController:viewController1];
    navviewController1.title = @"Title1";


    viewController2 = [[[HowItWorksViewController alloc] initWithNibName:@"viewController2" bundle:nil] autorelease];
    navviewController2=[[UINavigationController alloc]initWithRootViewController:viewController2];
    navviewController2.title = @"Title2";
    self.tabBarController.viewControllers = [NSArray arrayWithObjects:navviewController1, navviewController2, nil];

    self.window.rootViewController = self.tabBarController;

    [self.window makeKeyAndVisible];
}
-(void)setRootViewControllerTab2{

    UIViewController *viewController3, *viewController4;
    UINavigationController *navviewController3 , *navviewController4;
    /////TAB 2/////***********
    viewController3 = [[[CUHomeViewController alloc] initWithNibName:@"viewController3" bundle:nil] autorelease];
    navviewController3=[[UINavigationController alloc]initWithRootViewController:viewController3];
    navviewController3.title = @"Title3";

    viewController4 = [[[CUFavouritiesViewController alloc] initWithNibName:@"viewController4" bundle:nil] autorelease];
    navviewController4=[[UINavigationController alloc]initWithRootViewController:viewController4];
    navviewController4.title = @"Title4";
    self.tabBarController2.viewControllers = [NSArray arrayWithObjects:navviewController3, navviewController4, nil];

    self.window.rootViewController = self.tabBarController2;

    [self.window makeKeyAndVisible];
}

AppDelegate以下のようなオブジェクトで上記のメソッドを呼び出します...

例:メソッドでその時点でクリックされた button1 は、次のコードを記述します...

- (IBAction)btn1_Clicked:(id)sender{
        AppDelegate *objApp = (AppDelegate *)[[UIApplication sharedApplication] delegate];
        [objApp setRootViewControllerTab1];
}
于 2013-07-10T09:03:33.267 に答える