3

私のアプリには現在があり、ボタンがクリックされたときにある時点でUINavigationControllerを押したいと思います。UITabBarController私は(プログラムではなく)InterfaceBuilderでそれを作成しようとしています。

すべてのオンラインチュートリアルは、タブバーベースのアプリを作成する方法を示しています。これには、をドラッグする必要がありますがUITabBarControllerMainWindow.xibこれは明らかに私が望んでいることではありません。

私がしたことは、を作成しUIViewController、そのnibファイルをドラッグして作成することでしたUITabBarController。これをナビゲーションコントローラーにプッシュするUIViewControllerと、空のビュー(空のビュー)が表示されます。ビューコントローラでビューを削除すると、アプリがクラッシュします。独自のビューの代わりにUIViewControllerをロードするように指示するにはどうすればよいですか?UITabBarController

私に反対票を投じた人たちのために:少なくともコメントを提供するのはまともだろう。その質問は悪い質問ではありません。質問は、UITabBarControllerを非正統的な方法で使用する方法についての提案を求めています。私はほとんどの提案を試しましたが、うまくいきません。反対票を投じる場合は、少なくともコメントを書いてください。

4

7 に答える 7

14

あなたはこれがあなたを助けるかもしれないのを見ることができます

これがアプリのあり方です。-ナビゲーションコントローラー-ルートビューコントローラー-その他のビューコントローラー-タブバーコントローラー-タブの下の最初のVC-タブの下の2番目のVC-タブの下の3番目のVC-その他のビューコントローラー

ViewControllerをUITabBarControllerにプッシュするViewControllerで、これを使用します

//create a UITabBarController object
UITabBarController *tabBarController=[[UITabBarController alloc]init];

//FirstViewController and SecondViewController are the view controllers you want on your UITabBarController (Number of view controllers can be according to your need)
FirstViewController *firstViewController=[[FirstViewController alloc]initWithNibName:@"FirstViewController" bundle:nil];
SecondViewController *secondViewController=[[SecondViewController alloc]initWithNibName:@"SecondViewController" bundle:nil];

//adding view controllers to your tabBarController bundling them in an array
tabBarController.viewControllers=[NSArray arrayWithObjects:firstViewController,secondViewController, nil];

//navigating to the UITabBarController that you created
[self.navigationController pushViewController:tabBarController animated:YES];
于 2012-08-23T12:52:32.230 に答える
1

このチュートリアルが役立つかもしれません。サンプルコードが付属しています。

于 2012-08-23T09:09:04.740 に答える
0

こんにちは、アプリデリゲートでnavコントローラーとtabBarコントローラーの両方を作成します。最初にnavControllerをルートビューに追加します。

[self.window addSubview:navigationController.view];  

タブバーを追加するときはいつでも、navControllerを削除してtabBarControllerを追加します。

-(void)addTabBarController
{
    AppDelegate *appdelegte =(AppDelegate*)[[UIApplication sharedApplication]delegate];

    [[[appdelegte navigationController] view]removeFromSuperview];

    [[appdelegte window]addSubview:[[appdelegte tabcontroller]view]];

    [[appdelegte tabcontroller]setSelectedIndex:0];
}  

問題が発生した場合は、もう一度お問い合わせください。

于 2012-08-18T14:09:24.040 に答える
0

YourViewコントローラーで、tabBarControllerのIBOutletを作成します

.hファイル内

#import <UIKit/UIKit.h>

@interface YourView : UIViewController
{
    IBOutlet UITabBarController *tabBarController;
}
-(IBAction)loadTabBar:(id)sender;
@end  

および.mファイル

#import "YourView.h"
#import "FirstViewController.h"
#import "SecondViewController.h"

@implementation YourView

-(IBAction)loadTabBar:(id)sender
{
    FirstViewController *firstView = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
    SecondViewController *secondView = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
    tabBarController = [[UITabBarController alloc] init];
    tabBarController.viewControllers = [NSArray arrayWithObjects:firstView, secondView, nil];
    [self.navigationController pushViewController:tabBarController animated:YES];
}
@end  

tabBarControllerは、.xibファイルのtabBarControllerIBOutletに接続する必要があります。UITabBarControllerそしてUITabBarController、、という名前FirstViewControllerの2つのViewControllerを使用しSecondViewControllerます。

于 2012-08-20T05:17:40.077 に答える
0

タブバーコントローラーのuiviewを取得するということは、タブを備えたインターフェイスビルダーを作成し、そのタブバーをクラスに追加することを意味します。

たとえば、そのuiviewの3つのタブのタブバーuiviewを取得し、インターフェイスビルダーの3つのボタンを取得します

そのクラスのすべてのナビゲーションに対して、このuiviewクラスを追加する必要があります

-(IBAction)firt_button_pressed:(id)sender
{

}

-(IBAction)second_button_pressed:(id)sender
{

}
于 2012-08-22T07:24:15.880 に答える
0

私はこれに似た何かをしたことを覚えています...

あなたがそれに「プッシュ」するためUITableViewControllerに使用するつもりなら、私はこれを行うためのカスタムを作成しなければなりませんでした。UINavigationController

Interface Builderでのみそれを行うのは少し難しいかもしれません、私がそれをやってからしばらく経ちました、私はそれが正しく進むのは少し悪夢だったことを思い出します。

于 2012-08-22T13:04:57.910 に答える
0

問題は、がどこかで述べたように、XIBにUIViewが接続されていないことです。UIViewがXIBファイルで削除され、UITabBarControllerが追加された場合、XIBのviewプロパティをのビューに接続する必要がありUITabBarControllerます。接続して動作しました。それが私がSIGTRAPを入手した理由です。

于 2012-08-24T23:59:01.810 に答える