UITabBar + Nav,

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.