Use of tabbar In the paging bar for iOS beginners (4)

Source: Internet
Author: User
Use of tabbar In the paging bar of IOS beginners Development

If the original Yusong Momo article is reprinted, please note: Reprinted to my independent domain name blog Yusong Momo program Research Institute, Original address: http://www.xuanyusong.com/archives/602


Generally, many horizontal buttons are placed at the bottom of the screen. You can click different buttons to switch the view displayed on the screen, tablebar can be customized by using its own method or inheriting its own method. Today we will mainly discuss the simple use of tablebar provided by the system.

As shown in, up to five tablebar screens can be placed in the system. If there are more than five tablebar screens, a more button is automatically generated, which will display the exceeded ones in the form of a list, paste the code for analysis.

Nsmutablearray * controllers: stores every item in tablebar and displays it on the screen.

Nsarray * Item: stores the names that need to be displayed in the pagination bar, and uses the for loop to traverse them in sequence to add them to the display view.

Tableviewcontroller: controls the display view after clicking tablebar.

Add it to the display view ..

Tableviewappdelegate. m

# Import "tableviewappdelegate. H "# import" tableviewcontroller. H "@ implementation tableviewappdelegate @ synthesize window = _ window;-(bool) Application :( uiapplication *) Application metadata :( nsdictionary *) launchoptions {nsmutablearray * controllers = [nsmutablearray array]; nsarray * Item = [nsarray arraywithobjects: @ "Yu Song Momo", @ "ruowova", @ "Xiao cute", @ "", @ "", @" Apple", @ "happy music", @ "sushi roll", nil]; // Number of arrays int COUNT = [item count]; for (INT I = 0; I <count; I ++) {// create tableviewcontroller * tabviewcontroller = [[tableviewcontroller alloc] initcontroller: [item objectatindex: I]; // set the title [tabviewcontroller settitle: @ "Yusong Momo Program World"]; // bind a tabviewcontroller to respond to the event. Click the event uinavigationcontroller * nav = [[uinavigationcontroller alloc] initwithrootviewcontroller: tabviewcontroller]; // set the title nav. title = [item objectatindex: I]; // sets the image nav. tabbaritem. image = [uiimage imagenamed: @ "title.png"]; // set the style to the default style nav. navigationbar. barstyle = uibarstyledefault; // Add this uinavigationcontroller [controllers addobject: nav]; // release the object [nav release];} // create uitabbarcontroller, add the displayed content to uitabbarcontroller * bar = [[uitabbarcontroller alloc] init]; Bar. viewcontrollers = controllers; Bar. customizableviewcontrollers = controllers; // Add it to the display window [self. window addsubview: bar. view]; // override point for customization after application launch. [self. window makekeyandvisible]; return yes;} @ end

As shown in, redundant items are displayed in a list.


-(ID) initcontroller :( nsstring *) STR: used for initialization. The display content is passed in. When you create a tablebar, enter the name as a parameter so that you can click the button during each switchover. In this example, the content displayed on the top will be switched when you click the button.

-(Void) viewdidload: This method is very important. If you do not press the button, it will be reloaded because the controller of each item is set to tableviewcontroller. If the content displayed on each page is not clear, you can write several controller classes to control the switching of each table page.

I will not explain the code in it much. The previous blog posts have detailed descriptions ~

Tableviewcontroller. m

# Import "tableviewcontroller. H "@ implementation tableviewcontroller-(ID) initcontroller :( nsstring *) STR {self = [Super init]; If (Self) {// click a new tag each time, assign the displayed content value to showstring = STR;} return self;}-(void) viewdidload {[Super viewdidload]; // create the label view uilabel * label = [[uilabel alloc] initwithframe: cgrectmake (0, 0,320, 30)]; // set the label of the displayed content. TEXT = [nsstring stringwithformat: @ "% @", @ "selected", showstring]; // set the background color label. backgroundcolor = [uicolor bluecolor]; // set the text color label. textcolor = [uicolor whitecolor]; // sets the center label of the display position. textalignment = uitextalignmentcenter; // set the font size label. font = [uifont fontwithname: [[uifont familynames] objectatindex: 10] size: 20]; // create an image view uiimageview * imageview = [[uiimageview alloc] initwithframe: cgrectmake (100,150,120,120)]; // set the resource path for displaying the image [imageview setimage: [uiimage imagenamed: @ "0.jpg"]; // Add it to the view [self. view addsubview: Label]; [self. view addsubview: imageview]; // release object [label release]; [imageview release];}-(void) viewdidunload {[Super viewdidunload]; // release any retained subviews of the main view. // e.g. self. myoutlet = nil;} @ end


In the end, if you still think that I am not writing enough details, it doesn't matter if I post the source code. You are welcome to discuss and study Yu Song Momo, hoping to make progress together with everyone. Today, I went out to play football with my colleagues. It's so cool to get sweaty ~~ Momo recommends that you exercise more in your spare time, which is the cost of the revolution ~~

: Http://www.xuanyusong.com/archives/602

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.