Since IOS6, Apple has introduced the Storyborad technology to replace the nib, so that the amount of code does not write a lot, but also relatively concise. However, from the perspective of learning, Antioch that the use of nib, although more code, but for the knowledge and principles of the point of view, I think nib writing is very good. When using Storyborad's writing, if the segue scene is more, the setting has the problem, it will cause some abnormal occurrence, increase the difficulty of debugging. The following Antioch personally tested both NIB and storyboard's two-way demo. Below the difference between the simple comparison of the next, for the need to master the user to understand.
Demo is as follows
The two ways of writing a table view are different when cell cells are selected. The following are the Antioch from the VIEWCONTROLLER.M and citiesviewcontroller.m sides, respectively.
I. Comparison of code notation
Viewcontroller.m
NIB notation
#pragma mark-Implementing a Table View Delegate method
-(void) TableView: (UITableView *) TableView Didselectrowatindexpath: (Nsindexpath *) Indexpath
{
Nsinteger row = [Indexpath row];
Citiesviewcontroller *citiesviewcontroller = [[Citiesviewcontroller alloc] initwithstyle:uitableviewstyleplain];
NSString *selectname = [Self.listdata objectatindex:row];
Citiesviewcontroller.listdata = [Self.dictdata objectforkey:selectname];
Citiesviewcontroller.title = Selectname;
[Self.navigationcontroller Pushviewcontroller:citiesviewcontroller Animated:yes];
}
Storyboard notation
Trigger When table View Row is selected
-(void) Prepareforsegue: (Uistoryboardsegue *) Segue Sender: (ID) sender
{
if ([Segue.identifier isequaltostring:@ "Showselectedprovince"])
{
Citiesviewcontroller *citiesviewcontroller = Segue.destinationviewcontroller;
Nsinteger SelectedIndex = [[Self.tableview indexpathforselectedrow] row];
NSString *selectname = [Self.listdata objectatindex:selectedindex];
Citiesviewcontroller.listdata = [Self.dictdata objectforkey:selectname];
Citiesviewcontroller.title = Selectname;
}
}
Citiesviewcontroller.m
NIB notation
#pragma mark-Implementing a Table View Delegate method
-(void) TableView: (UITableView *) TableView Didselectrowatindexpath: (Nsindexpath *) Indexpath
{
Nsinteger row = [Indexpath row];
Detailviewcontroller *detailviewcontroller = [[Detailviewcontroller alloc] initwithnibname:@ "DetailViewController" Bundle:nil];
Nsdictionary *dict = [Self.listdata objectatindex:row];
Detailviewcontroller.url = [dict objectforkey:@ "url"];
NSString *name = [dict objectforkey:@ "name"];
Detailviewcontroller.title = name;
[Self.navigationcontroller Pushviewcontroller:detailviewcontroller Animated:yes];
}
Storyboard notation
Trigger When table View Row is selected
-(void) Prepareforsegue: (Uistoryboardsegue *) Segue Sender: (ID) sender
{
if ([Segue.identifier isequaltostring:@ "showselectedcity"])
{
Detailviewcontroller *detailviewcontroller = Segue.destinationviewcontroller;
Nsinteger SelectedIndex = [[Self.tableview indexpathforselectedrow] row];
Nsdictionary *dict = [Self.listdata objectatindex:selectedindex];
Detailviewcontroller.url = [dict objectforkey:@ "url"];
NSString *name = [dict objectforkey:@ "name"];
Detailviewcontroller.title = name;
}
}
Two. Operation mode
Storyboard Navigation Browser, do not need code definition, directly select a Viewcontroller, and then select menu operation
Editor-->embed in--->navigation Controller
When navigating from one viewcontroller to another viewcontroller, push directly on the interface, you need to select the segue in the middle of the connection, open the generic inspector, and then specify in the identifier attribute, as Showselectedprovinces
Table View cell events in iOS summary of two ways to use NIB and storyboard