Function: Click on the list item, create a new view with the list string as a parameter, the new view can have a Back button to return to the previous view by default
////main.m//Hello////Created by Lishujun on 14-8-28.//Copyright (c) 2014 Lishujun. All rights reserved.//#import<UIKit/UIKit.h>//-------------View controller that accepts parameters-------------@interfaceTestviewcontroller:uiviewcontroller@end@implementationTestviewcontroller-(Testviewcontroller *) Initwitharg: (NSString *) arg{NSLog (@"%@", ARG); returnSelf ;}-(void) loadview{//Create a View objectUIView *contentview =[[UIView Alloc]initwithframe:[[uiscreen Mainscreen] applicationframe]; Contentview.backgroundcolor=[Uicolor Lightgraycolor]; Self.view=Contentview;}@end//--------------View Controller Object--------------@interfaceHelloworldviewcontroller:uiviewcontroller <uitableviewdatasource, uitableviewdelegate>{UITableView*TableView; Nsarray*Array;}@end@implementationHelloworldviewcontroller-(Helloworldviewcontroller *) init{Array= [[Nsarray alloc]initwithobjects:@"oops",@"Hello",@" World", nil]; returnSelf ;}-(void) loadview{//Create a View objectUIView *contentview =[[UIView Alloc]initwithframe:[[uiscreen Mainscreen] applicationframe]; Contentview.backgroundcolor=[Uicolor Lightgraycolor]; Self.view=Contentview; TableView=[[UITableView alloc]initwithframe:[[uiscreen Mainscreen] applicationframe]; [Self.view Addsubview:tableview]; Tableview.datasource=Self ; TableView.Delegate=Self ;}//--------The method that the DataSource interface must implement to populate the table------------(Nsinteger) Numberofsectionsintableview: (UITableView *) tableview{return 1;//set Number of list partitions}-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) section{return[Array Count];//set list length}-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{//Generate list cells (reuse existing units as much as possible) StaticNSString *simpletableidentifer =@"Simpletableidentifer"; UITableViewCell*cell =[TableView Dequeuereusablecellwithidentifier:simpletableidentifer]; if(Cell = =Nil) {Cell=[[UITableViewCell Alloc]initwithstyle:uitableviewcellstyledefault Reuseidentifier:simpletableidentifer]; } Cell.textLabel.text=Array[indexpath.row]; returncell;}//----------method for implementing the delegate interface for Operation----------------(void) TableView: (UITableView *) TableView Didselectrowatindexpath: (Nsindexpath *) indexpath{//Row Check EventNSString *rowvalue =Array[indexpath.row]; [TableView Deselectrowatindexpath:indexpath Animated:yes]; //Uncheck State[Self.navigationcontroller Pushviewcontroller:[[testviewcontroller Alloc]initwitharg:rowvalue] Animated:YES];} @end//----------------The delegate object--------------------@interfaceHelloworldappdelegate:nsobject <UIApplicationDelegate>{iboutlet UIWindow*window;} @property (nonatomic, retain) UIWindow*window; @property (nonatomic, retain) Uinavigationcontroller*nav;@end@implementationhelloworldappdelegate@synthesizewindow;@synthesizenav;-(void) Applicationdidfinishlaunching: (UIApplication *) application{Self.window=[[UIWindow alloc] Initwithframe:[[uiscreen Mainscreen]bounds]]; Helloworldviewcontroller*viewcontroller =[[Helloworldviewcontroller alloc]init]; Self.nav=[[Uinavigationcontroller Alloc]initwithrootviewcontroller:viewcontroller]; Self.window.rootViewController=Self.nav; [Self.window makekeyandvisible];}@end//---------------Program Entry---------------------intMainintargcChar*argv[]) {@autoreleasepool {returnUiapplicationmain (argc, argv, Nil,@"helloworldappdelegate"); }}
Ios:nav+table Combination