Storyboard is a new feature of iOS 5, designed to replace the historic nib/xib, storyboard is not so familiar to children who are accustomed to XIB files. After two days of research, have some experience, here to share.
First, how to use storyboard simple implementation of the push page, the steps are as follows:
1. Create a Singleview application application with storyboard as shown in figure.
The created application has automatically created a well-connected viewcontroller with Mainstoryboard.
2. In Mainstoryboard, select Viewcontroller and drag into TableView and Tableviewcell, and set the Tableviewcell style to basic,identifier as cell, If you want to customize the cell, you need to select Custom, as shown below, and then insert a navigationcontroller:
Don't forget to connect DataSource and delegate.
Now it can be encoded, in VIEWCONTROLLER.M:
#pragmamark-uitableviewdatasource
-(Nsinteger) TableView: (uitableview*) TableView numberofrowsinsection: (Nsinteger) section{
RETURN1;
}
-(uitableviewcell*) TableView: (uitableview*) TableView Cellforrowatindexpath: (nsindexpath*) indexpath{
Staticnsstring*cellidentifier = @ "Cell";
Uitableviewcell*cell = [TableView dequeuereusablecellwithidentifier:cellidentifier];
if (cell = = nil)
{
cell= [[Uitableviewcellalloc]initwithstyle:uitableviewcellstyledefault
Reuseidentifier:cellidentifier];
Cell.accessorytype=uitableviewcellaccessorydisclosureindicator;
}
cell.textlabel.text=@ "topic";
Returncell;
}
3. Now implement simple push function:
Open the Mainstoryboard file again, drag a new one into the Tableviewcontroller, and create a new Topictableviewcontroller h file and M file in the right project, Select the Tableviewcontroller in Mainstoryboard, set its class to Topictableviewcontroller, and set the cell to TableView as above.
* Right-click on the previous Viewcontroller cell and connect push to the newly dragged TableView Controller, as shown below:
This time the operation will be able to correctly push to the new TableView page.
If you want to do something on the push page, you can encode it in the viewcontroller.m file:
-(void) Prepareforsegue: (uistoryboardsegue*) Segue sender: (ID) sender
{
if ([[segueidentifier]isequaltostring:@ "showsomething"]) {
DoSomething you want
Uialertview*alertview = [[uialertviewalloc]initwithtitle:nilmessage:@ "Test] delegate:nilcancelbuttontitle:@" OK " Otherbuttontitles:nil,nil];
[Alertviewshow];
}
}
Remember to set the push segue, where I set it to showsomething.
The run can see the Testalert box pop up on the push page, as shown in the figure:
Second, get the object in the specified storyboard
The previous steps are completed in step first to second, and then the third step is completed to the * symbol, this time to see a separate new TableView controller, how to get it. Very simple, first, Mainstoryboard Select the new TableView controller, set its identifier to Topictableviewcontroller, as shown:
Next, in the function you need to use it, the following:
-(void) Presenttimelineviewcontroller: (BOOL) animated
{
Uistoryboard*storyboard = [uistoryboardstoryboardwithname:@ "Mainstoryboard" bundle:nil];
Topictableviewcontroller*topicviewcontroller = [storyboardinstantiateviewcontrollerwithidentifier:@] Topictableviewcontroller "];
。。。
[Self.navigationControllerpushViewController:topicViewController