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