iOS Development-uinavigationcontroller Simple implementation

Source: Internet
Author: User

Navigation bar or navigation section is now basically standard in the app, similar to the parent-child level of taste in the inside, Uinavigationcontroller is responsible for simplifying this implementation function, is a more commonly used in iOS development of a container view controller, Many people use, it is relatively easy to achieve, you can first look at a picture to understand Navigationcontroller:

Interface Layout

It looked very tall on the top, below to see a personal, drag from the control library into a navigation Controller, and then create a new two viewcontroller:

A navigationcontroller can be used directly, it needs to be demonstrated, and a view is added later:

Demo Implementation

The data is initialized in the Viewcontroller of the home page:

-(void) viewdidload {    [super viewdidload];    Additional setup after loading the view, typically from a nib.    Data=[[nsarray Alloc] initwithobjects:@ "front", @ "back end", nil];    [Self.tableview setdelegate:self];    [Self.tableview setdatasource:self];}

Set number of groups, number of rows and content:

Number of}//groupings-(Nsinteger) Numberofsectionsintableview: (UITableView *) tableview{    return 1;} Number of rows grouped-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) section{    return [data Count];} Return content in TableCell-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{        UITableViewCell *cell=[[uitableviewcell alloc] Initwithstyle:uitableviewcellstyledefault Reuseidentifier:nil];        [Cell.textlabel Settext:data[indexpath.row]];    return cell;}

Set line height:

-(CGFloat) TableView: (UITableView *) TableView Heightforrowatindexpath: (Nsindexpath *) indexpath{    return 40;}

To set jump events:

-(void) TableView: (UITableView *) TableView Didselectrowatindexpath: (Nsindexpath *) indexpath{    Nsarray * Notificationdata=[[nsarray Alloc]init];    Nsinteger Index=[self.tableview Indexpathforselectedrow].row;    if (index==0) {        notificationdata=[[nsarray alloc]initwithobjects:@ "Android", @ "IOS", @ "JS", nil];    } else{        notificationdata=[[nsarray alloc]initwithobjects:@ "Java", @ "C #", @ "Python", nil];    }        Secondviewcontroller *controller = [Self.storyboard instantiateviewcontrollerwithidentifier:@ "SecondStoryID"];    Controller.data=notificationdata;    [Self.navigationcontroller Pushviewcontroller:controller animated:yes];    }

Details of the Viewcontroller and the first similar, has written a lot of tableview implementation, direct code, do not explain:

-(void) viewdidload {    [super viewdidload];    Do any additional setup after loading the view, typically from a nib.    } -(void) Notificationhandler: (nsnotification *) notification{    self.data=[notification object];} Number of groupings-(Nsinteger) Numberofsectionsintableview: (UITableView *) tableview{    return 1;} Number of rows grouped-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) section{    return [ Self.data count];} Return content in TableCell-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{    UITableViewCell *cell=[[uitableviewcell alloc] Initwithstyle:uitableviewcellstyledefault Reuseidentifier:nil];    [Cell.textlabel Settext:self.data[indexpath.row]];    NSLog (@ "%@", Self.data[indexpath.row]);    return cell;} -(CGFloat) TableView: (UITableView *) TableView Heightforrowatindexpath: (Nsindexpath *) indexpath{    return 40;}

But in the details of the header file to set up:

@interface Secondviewcontroller:uiviewcontroller@property (Nonatomic,strong) Nsarray *data; @end

The effect of the final implementation is as follows:

The green background navigation bar requires personal settings:

iOS Development-uinavigationcontroller Simple implementation

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.