UITabBar + Nav,
In actual project development, there are always several common templates. In the past few days, I hope you can give me some valuable comments! In the past few months, the most commonly used template is the Nav + UITabBar template. In actual projects, I focus more on pure code and prefer not to drag controls. As for the advantages and disadvantages, I will not talk about it here, let's get down to the truth.
First, create a blank set in AppDelegate. m:
Self. window = [[UIWindow alloc] initWithFrame: [UIScreen mainScreen] bounds];
Initialize UITabBarController
Self. tabBarController = [[UITabBarController alloc] init];
Create two view controllers:
FirstViewController * one = [[FirstViewController alloc] init];
SecondViewController * second = [[SecondViewController alloc] init];
Create two navigation controllers and let them control their respective view controllers:
UINavigationController * navFirst = [[UINavigationController alloc] initWithRootViewController: one];
UINavigationController * navSecond = [[UINavigationController alloc] initWithRootViewController: second];
Let tabBarController include the two navigation controllers:
[Self. tabBarController addChildViewController: navFirst];
[Self. tabBarController addChildViewController: navSecond];
Refined customization of view controllers:
One. title = @ "Contact ";
One. tabBarItem = [[UITabBarItem alloc] initWithTitle: @ "one" image: [UIImage imageNamed: @ ""]
SelectedImage: nil];
Second. title = @ "favorites ";
Second. tabBarItem = [[UITabBarItem alloc] initWithTitle: @ "second" image: nil selectedImage: nil];
Set the main view on the blank set to tabBarController:
[Self. tabBarController addChildViewController: navSecond];
Change the set to Red:
Self. window. backgroundColor = [UIColor redColor];
Display Set:
[Self. window makeKeyAndVisible];
Create a Level 2 page in FirstViewController
Create navigation bar:
UIBarButtonItem * rightButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemSearch target: self action: @ selector (selectRightAction :)];
Redirection method:
-(Void) selectRightAction :( id) sender
{
BackViewController * backButton;
BackButton = [[BackViewController alloc] initWithNibName: @ "BackViewController" bundle: nil]; backButton. title = @ "second view layer"; [self. navigationController pushViewController: backButton animated: NO];
}
Code example: http://download.csdn.net/detail/it_ds/8568545