Learning notes: Use of the tab bar Control

Source: Internet
Author: User

Note: The tab bar is not the tab bar controller. The tab bar inherits the uiview, so you can add it to the viewcontroller. You can add the view to another view. The tab bar controller is used to create a view.

Uitabbar must be defined in XX. h and the uitabbardelegate protocol must be referenced.

@ Interface loginviewcontroller: uiviewcontroller <uitabbardelegate>

{

Uitabbar * tabbar;

}

@ Property (nonatomic, retain) uitabbar * tabbar;

 

XX. m

 

@ Synthesize tabbar;

 

-(Void) viewdidload

{

// Load the tab bar

 

Cgrect footframe = cgrectmake (0,420,320, 60 );

Tabbar = [[uitabbar alloc] initwithframe: footframe];

Uitabbaritem * Item1 = [[uitabbaritem alloc] initwithtabbarsystemitem: 1 Tag: 0];

Uitabbaritem * item2 = [[uitabbaritem alloc] initwithtabbarsystemitem: 2 Tag: 1];

Nsarray * items = [[nsarray alloc] initwithobjects: Item1, item2, nil];

[Tabbar setitems: Items animated: Yes];

[Item1 release];

[Item2 release];

[Items release];

[Self. View addsubview: tabbar];

Tabbar. Delegate = self; // specify its proxy method. Otherwise, the method does not work.

[Tabbar release];

 

}

 

 

 

-(Void) tabbar :( uitabbar *) tabbar didselectitem :( uitabbaritem *) item

{

Nslog (@ "selected is % d", item. Tag );

Nsstring * MSG = [[nsstring alloc] initwithformat: @ "selected is % d", item. Tag];

Uialertview * Alert = [[uialertview alloc] initwithtitle: @ "a" message: MSG delegate: Self cancelbuttontitle: @ "OK" otherbuttontitles: nil, nil];

[Alert show];

[MSG release];

[Alert release];

}

 

Learning notes: Use of the tab bar Control

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.