I. project structure
Create an empty project
Ii. Main Code
1. AppDelegate. m
-(BOOL) application :( UIApplication *) application didfinishlaunchingwitexceptions :( NSDictionary *) launchOptions {self. window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]; UITabBarController * tabBarController = [[UITabBarController alloc] init]; firstViewController * one = [[FirstViewController alloc] init]; one. title = @ "Contact"; one. tabBarItem = [[UITabBarItem alloc] tags: custom tag: 0]; UINavigationController * navFirst = [[UINavigationController alloc] initWithRootViewController: one]; [tabBarController addChildViewController: navFirst]; secondViewController * two = [[SecondViewController alloc] init]; two. title = @ "favorites"; two. tabBarItem = [[UITabBarItem alloc] tags: custom tag: 1]; UINavigationController * navSecond = [[UINavigationController alloc] metadata: two]; [tabBarController addChildViewController: navSecond]; self. window. rootViewController = tabBarController; self. window. backgroundColor = [UIColor whiteColor]; [self. window makeKeyAndVisible]; return YES ;}
2. FirstViewController. m
-(Void) viewDidLoad {[super viewDidLoad]; UIBarButtonItem * rightButton = [[UIBarButtonItem alloc] failed: UIBarButtonSystemItemAdd target: self action: @ selector (selectRightAction :)]; self. navigationItem. authorization = rightButton;}-(void) selectRightAction :( id) sender {ChildViewController * childViewController; childViewController = [[ChildViewController alloc] handler: @ "ChildViewController" bundle: nil]; childViewController. title = @ "add contact"; [self. navigationController pushViewController: childViewController animated: YES];}
3. SecondViewController. m
Default content
4. ChildViewController. m
Default content
Iii. Running Effect
1. Initial Interface
2. Go to the subview of the first view.
3. Switch to the second view.