Function: Create a list, populate the table with an array, and support select list rows
////main.m//Hello////Created by Lishujun on 14-8-28.//Copyright (c) 2014 Lishujun. All rights reserved.//#import<UIKit/UIKit.h>//View Controller Objects@interfaceHelloworldviewcontroller:uiviewcontroller<uitableviewdatasource, uitableviewdelegate>{Nsarray*Array; UITableView*TableView; //without a @property declaration, you can't use self for reference? I have to figure out what's the difference .}@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; //Create TableViewTableView =[[UITableView alloc]initwithframe:[[uiscreen Mainscreen] applicationframe]; [TableView setdatasource:self]; [TableView setdelegate:self]; //TableView Adding to the content view[Contentview Addsubview:tableview];}//--------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----------------(Nsindexpath *) TableView: (UITableView *) TableView Willselectrowatindexpath: (Nsindexpath *) indexpath{//Row to select the previous event, the following code implementation is the choice to implement canceling the first row, that is, not allowed to select if(Indexpath.row = =0) { returnNil; } Else { returnIndexpath; }}-(void) TableView: (UITableView *) TableView Didselectrowatindexpath: (Nsindexpath *) indexpath{//Row Check EventNSString *rowvalue =Array[indexpath.row]; [TableView Deselectrowatindexpath:indexpath Animated:yes]; //Uncheck StateNSLog (@"%@", Rowvalue); }@end//Delegate Object@interfaceHelloworldappdelegate:nsobject <UIApplicationDelegate>{iboutlet UIWindow*window;} @property (nonatomic, retain) UIWindow*window;@end@implementationhelloworldappdelegate@synthesizewindow;-(void) Applicationdidfinishlaunching: (UIApplication *) application{Self.window=[[UIWindow alloc] Initwithframe:[[uiscreen Mainscreen]bounds]]; Helloworldviewcontroller*viewcontroller =[[Helloworldviewcontroller alloc]init]; Self.window.rootViewController=Viewcontroller; [Self.window makekeyandvisible];}@end//Program EntryintMainintargcChar*argv[]) {@autoreleasepool {returnUiapplicationmain (argc, argv, Nil,@"helloworldappdelegate"); }}
IOS: Implementing table Fill and select operations