1

最初の 4 つの画面がナビゲーション ベースの iPhone アプリを開発しています。

5 番目の画面から、デザインがタブバー ベースのものに変更されました。このタブバー ベースのセクションでは、各タブのサブビューをナビゲートできます。

どうすればこれを実装できますか?

タブバー Controller-In appDelegate または他のファイルのどこで宣言しますか?

4

4 に答える 4

1

app-delegateクラスにオブザーバーを追加できます

[[NSNotificationCenter defaultCenter] addObserver:self 
                                             selector:@selector(youMethod)        
                                                 name:@"loginSucess" 
                                               object:nil];


- (void)youMethod
{
    UINavigationController *controller = [[[UINavigationController alloc] initWithRootViewController:self.tabBarController] autorelease];


    self.window.rootViewController = controller;    
    [self.window makeKeyAndVisible];
}

そして、アクションについては、このように呼び出すことができるタブバーを追加したい場合

    [[NSNotificationCenter defaultCenter] postNotificationName:@"loginSucess" object:nil];
于 2012-05-23T05:39:18.527 に答える
0

アプリデリゲートで、最初の5つの画面(画面1から5)を宣言しました。画面5のボタンで、タブバーを起動するとします。次の手順を実行します。

//Create the tab bar controller
UITabBarController *tabBar = [[UITabBarController alloc] init];
//Create the 5 new view controllers
UIViewController *cont_1 = [[UIViewController alloc] init];

//Add them to array
NSArray *arr = [NSArray arrayWithObjects:cont_1, cont_2, ... , nil]
[tabBar setViewControllers:arr];

//Now push the tab bar controller
[self.navigationController pushViewController:tabBar animated:YES];
于 2012-05-23T05:37:51.483 に答える
0

プログラムで Tabbar コントローラーを作成し、tabbarcontroller を navigationController に追加します。

MyFirstViewController *myFirstViewController = [[MyFirstViewController alloc] init];
MySecondViewController *mySecondViewController = [[MySecondViewController alloc] init];

myFirstViewController.array = self.array;


NSArray *array = [[NSArray alloc] initWithObjects:myFirstViewController, mySecondViewController, nil];
UITabBarController *tab = [[UITabBarController alloc] init];
tab.viewControllers = array;

[array release];

UITabBarItem *item1 = [[UITabBarItem alloc] initWithTitle:@"first title" image:nil tag:1];
UITabBarItem *item2 = [[UITabBarItem alloc] initWithTitle:@"second title" image:nil tag:2];

myFirstViewController.tabBarItem = item1;
mySecondViewController.tabBarItem = item2;



[self.navigationController pushViewController:tab animated:YES];

このコードを使用すると、これが役に立ちます..

于 2012-05-23T05:43:14.007 に答える
0

私も自分のアプリで同様の問題を抱えていましたが、最終的に別の UIViewController をプッシュし、UITabBarController ビューをサブビューとして追加することにしました。

あなたが4番目の画面にいるとき、UIViewControllerでもある5番目の画面に移動します。そして、私はu hv 3タブを想定しています。

この UIViewController の viewDidLoad で

UITabBarController *tabBarController = [[UITabBarController alloc] init];
UIViewController1 *objUIViewController1 = [[UIViewController alloc] initWithNibName:@"UIViewController1" bundle:nil];
UIViewController2 *objUIViewController2 = [[UIViewController alloc] initWithNibName:@"UIViewController2" bundle:nil];
UIViewController3 *objUIViewController3 = [[UIViewController alloc] initWithNibName:@"UIViewController3" bundle:nil];

tabBarController.viewControllers = [NSArray arrayWithObjects:objUIViewController1, objUIViewController2, objUIViewController3, nil];
tabBarController.delegate = self;
[[tabBarController.viewControllers objectAtIndex:0] setTitle:@"Title1"];
[[tabBarController.viewControllers objectAtIndex:1] setTitle:@"title2"];

[self.view addSubview:tabBarController.view];
[UIViewController1 release];
[UIViewController2 release];
[UIViewController3 release];

それが役に立てば幸い。幸せなコーディング:)

于 2012-05-23T06:13:55.783 に答える