0

アプリにアクティベーション ページがあります。これは、すべてのユーザーがアプリをアクティベートするために必須です。アプリがアクティブ化されると、ユーザーはタブ付きバー ビューに移動します。

タブ バー アプリケーションを作成しました。ここで、ボタンをクリックしたときの activationView からタブ バーを呼び出そうとすると、黒い画面全体が表示されます。

- (IBAction)moveToActivateView:(id)sender {
    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    UITabBarController *tabBarController = [[UITabBarController alloc]init];
    [self.view addSubview:tabBarController.view];
    appDelegate.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    UIViewController *viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
    UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];

    self.tabBarController.viewControllers = @[viewController1, viewController2];
    appDelegate.window.rootViewController = self.tabBarController;
    [appDelegate.window makeKeyAndVisible];}
4

3 に答える 3

2

appDelegate で tabBarController のプロパティを作成し、そこにすべての ViewController を割り当ててから、ViewController から tabBarController を呼び出します

AppDelegate.h で

@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
@property (retain, nonatomic) IBOutlet UITabBarController *tabBarController;

AppDelegate.m で

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    [self makeTabBar];

    [self addInitialVIew];

    [self.window makeKeyAndVisible];

    return YES;
}  


-(void)makeTabBar
{    
    tabBarController = [[UITabBarController alloc] init];
    tabBarController.delegate=self;
    FirstViewController *firstVC =[[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];    

    UINavigationController *firstNC = [[UINavigationController alloc] initWithRootViewController:firstVC];
    firstNC.tabBarItem.title=@"Profile";
    firstVC.tabBarController.tabBar.tag = 0;


    SecondViewController *secondVC = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];

    UINavigationController *SecondNavController = [[UINavigationController alloc] initWithRootViewController:secondVC];    
    SecondNavController.tabBarItem.title = @"Search";
    secondVC.tabBarController.tabBar.tag = 1;


    NSArray *viewControllers =[[NSArray alloc]initWithObjects:firstNC,SecondNavController, nil];
    [tabBarController setViewControllers:viewControllers animated:NO];   
}

-(void) addInitialVIew
{    
    InitialViewController *initialViewController = [[InitialViewController alloc]initWithNibName:@"InitialViewController" bundle:nil];
    navigationController = [[UINavigationController alloc]initWithRootViewController:ViewController];
    [self.window addSubview:navigationController.view];
}

これで、InitialViewControlleryourTabBar を追加して削除できますInitialViewController

- (IBAction)switchToTabBarBtnPress:(id)sender
{
    AppDelegate *appdelegte =(AppDelegate*)[[UIApplication sharedApplication]delegate];

    [[[appdelegte navigationController] view]removeFromSuperview];

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

    [[appdelegte tabBarController]setSelectedIndex:0];
}

そして私の答えに従ってください

答え

于 2012-12-13T09:46:19.700 に答える
0

あなたのローカル変数tabBarControllerは同一ではなく、プロパティを隠していることに気づきましたself.tabBarControllerか? 新しい を作成し、このメソッドからのみアクセスできるUITabBarCotnrollerローカル変数に割り当てます。tabBarController次に、に操作(新しく作成したView Controllerを追加)などを行いself.tabBarControllerます。Self.tabBarControllerここでは簡単に nil になる可能性があります。しかし、それはUITabBarControllerまさにあなたが作成したものではありません。

そして、それはself.tabBarController(おそらくnil)としてウィンドウに割り当てるものですrootViewController

tabBarController'sビューをサブビューとして self.view に追加します。それ以外に、自分自身が何であるかはわかりませんが、タブバーのビューをサブビューとして手動で追加する必要はないと思います。ルートView Controllerを(適切に)設定するだけで十分です

于 2012-12-13T09:47:22.417 に答える
0

問題を解決するために、動的なタブバー アプリケーションを作成したいと考えています。したがって、ビューベースのアプリケーションを作成するだけです。View Controllerのviewdidloadメソッドにこれらのコードを入れます

tabbar1 = [[UITabBarController alloc] init];

    artist_tab_obj = [[artist_tab alloc] initWithNibName:@"artist_tab" bundle:nil];

    UINavigationController *tabItem1 = [[[UINavigationController alloc] initWithRootViewController: artist_tab_obj] autorelease];
    tabItem1.title=@"Artist";
    tabItem1.tabBarItem.image=[UIImage imageNamed:@"Icon1.png"];
    music_tab_obj = [[music_tab alloc] initWithNibName:@"music_tab" bundle:nil];

    UINavigationController *tabItem2 = [[[UINavigationController alloc] initWithRootViewController: music_tab_obj] autorelease];

    tabItem2.title=@"Music";
    tabItem2.tabBarItem.image=[UIImage imageNamed:@"Icon2.png"];

    shout_tab_obj = [[shout_tab alloc] initWithNibName:@"shout_tab" bundle:nil];

    UINavigationController *tabItem3 = [[[UINavigationController alloc] initWithRootViewController: shout_tab_obj] autorelease];

    tabItem3.title=@"Shout";
    tabItem3.tabBarItem.image=[UIImage imageNamed:@"Icon3.png"];
    schedule_tab_obj = [[schedule_tab alloc] initWithNibName:@"schedule_tab" bundle:nil];

    UINavigationController *tabItem4 = [[[UINavigationController alloc] initWithRootViewController: schedule_tab_obj] autorelease];

    tabItem4.title=@"Schedule";
    tabItem4.tabBarItem.image=[UIImage imageNamed:@"Icon4.png"];
    follow_tab_obj = [[follow_tab alloc] initWithNibName:@"follow_tab" bundle:nil];

    UINavigationController *tabItem5 = [[[UINavigationController alloc] initWithRootViewController: follow_tab_obj] autorelease];
    tabItem5.title=@"Follower";
    tabItem5.tabBarItem.image=[UIImage imageNamed:@"Icon5.png"];


    tabbar1.viewControllers = [NSArray arrayWithObjects:tabItem1, tabItem2,tabItem3,tabItem4,tabItem5,nil]; 

ユーザーの受け入れでは、はいボタンのアクションでこのコードを呼び出します。

[self.view insertSubview:tabbar1.view belowSubview: artist_tab_obj.view];
tabbar1.selectedIndex=1;
[self presentModalViewController:tabbar1 animated:YES]; 
于 2012-12-13T10:02:06.033 に答える