According to different needs, need to use the structure of tableview, but each cell inside, but also need their own style, so learned how to add their own cell definition of the tableview inside
First you create a class yourself, inherit UITableViewCell, and then create a new empty Xib file, and set the Class property to the corresponding name
Code section:
<pre name= "code" class= "OBJC" > #import "SettingViewController.h" #import "SettingViewCell.h" @interface Settingviewcontroller () @end @implementation settingviewcontroller@synthesize listarray =_listArray;-(ID) Initwithnibname: (NSString *) Nibnameornil Bundle: (NSBundle *) nibbundleornil{self = [Super Initwithnibname: Nibnameornil Bundle:nibbundleornil]; if (self) {//Custom initialization} return to self;} -(void) viewdidload{[Super Viewdidload]; Do any additional setup after loading the view from its nib. Nsarray *array = [Nsarray arraywithobjects: @ "Room settings", @ "Lighting settings", @ "Curtain Settings", @ "Scene settings", @ "Air conditioning settings", @ "Security settings", @ "Network Settings", nil]; _settingview.datasource =self; Set the data source method _settingview.delegate =self;//Set the proxy method Self.listarray =array; Note that due to memory management problems, if Self.listarray is not assigned, _listarray will be emptied and the program will crash}-(ibaction) backclicked: (ID) Sender {[ Self.navigationcontroller Poptorootviewcontrolleranimated:yes];} Data source Method-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (Nsinteger) section{return [_listarray count];} Delegate Method-(void) TableView: (UITableView *) TableView Didselectrowatindexpath: (nsindexpath *) indexpath{switch ( Indexpath.row) {case 0:break; Default:break; }}//Row display. Implementers should *always* try to reuse cells by setting each cell's reuseidentifier and querying for available reusable Cells with dequeuereusablecellwithidentifier://Cell gets various attributes set automatically based on table (separators ) and data source (accessory views, editing controls)-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowat Indexpath: (Nsindexpath *) indexpath{static NSString * Cellidentifier [email protected] "MyCell"; Settingviewcell *cell = (Settingviewcell *) [TableView dequeuereusablecellwithidentifier:cellidentifier]; if (cell = = nil) {Nsarray *array =[[nsbundle mainbundle] loadnibnamed:@ "Settingviewcell" Owner:self Options:nil] ; cell = [Array objecTATINDEX:0]; [Cell Setselectionstyle:uitableviewcellselectionstylegray]; } nsstring *text = _listarray[indexpath.row]; [[Cell Settingname] settext:text]; return cell;} -(void) didreceivememorywarning{[Super didreceivememorywarning]; Dispose of any resources the can be recreated.} -(void) Dealloc {[_back release]; [_settingview release]; [Super Dealloc];} @end