UIViewController 推送 UITabbarController 并推送 UivewController

UIViewController push UITabbarController and push UivewController

我的iOS app flow like UIViewController -----> UITabbarController having two view--->UIViewController1 and UIViewController2 ------after that UIViewController2-------- ->UIViewController3

好的,您也可以通过编程方式完成 以下是步骤: 第1步:

第 2 步: 在你的 ViewController.h 在此处为 转到标签栏 按钮

设置操作
#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

- (IBAction)gotoTab:(id)sender;

@end

在你的ViewController.m

#import "ViewController.h"
#import "FirstViewController.h"
#import "SecondViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];


}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];

}



- (IBAction)gotoTab:(id)sender {

    FirstViewController*  viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:[NSBundle mainBundle]];

    SecondViewController*  viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:[NSBundle mainBundle]];
    UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:@"View1" image:Nil tag:1];
    UITabBarItem *item2 = [[UITabBarItem alloc] initWithTitle:@"View2" image:Nil tag:2];

    UINavigationController *navigate, *navigate2;

    navigate = [[UINavigationController alloc] initWithRootViewController:viewController1];
    navigate2 = [[UINavigationController alloc] initWithRootViewController:viewController2];
    navigate.tabBarItem = item;
    navigate2.tabBarItem = item2;
    UITabBarController *tabBar = [[UITabBarController alloc] init ];

     tabBar.viewControllers = [NSArray arrayWithObjects:navigate,navigate2, nil];
    [self.navigationController pushViewController:tabBar animated:YES];


}
@end

第 3 步: 使用 xib 文件创建三个视图控制器

为FirstViewController、SecondViewController、ThirdViewController设置xib文件如下

第 4 步: 为 go to thirdview 按钮设置操作 第二ViewController.h

#import <UIKit/UIKit.h>

@interface SecondViewController : UIViewController

- (IBAction)gothird:(id)sender;

@end

秒ViewController.m

#import "SecondViewController.h"
#import "ThirdViewController.h"

@interface SecondViewController ()

@end

@implementation SecondViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



- (IBAction)gothird:(id)sender {

    ThirdViewController *third = [[ThirdViewController alloc] initWithNibName:@"ThirdViewController" bundle:[NSBundle mainBundle]];
    [self.tabBarController.navigationController pushViewController:third animated:YES];
}
@end