First attach it, a custom cell!
First step: Create a table
- (void) viewdidload{[Super Viewdidload]; //Do any additional setup after loading the view from its nib.self.table=[[uitableview Alloc] Initwithframe:cgrectmake (0,0, [[UIScreen Mainscreen] Bounds].size.width, [[UIScreen mainscreen] bounds].size.height) style: Uitableviewstylegrouped]; Self.table.Delegate=Self ; Self.table.dataSource=Self ; [Self.view addSubview:self.table];}-(Nsinteger) Numberofsectionsintableview: (UITableView *) tableview{return 5;}-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) section{nsinteger number; if(section==0) { number=2; }Else if(section==1) { number=3; }Else if(section==2) { number=5; }Else{ number=1; } returnNumber ;}-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{NSString*acell=@"Acell"; Zkbuttontableviewcell*button=[TableView Dequeuereusablecellwithidentifier:acell]; if(!button) {button=[[[nsbundle Mainbundle] Loadnibnamed:@"Zkbuttontableviewcell"owner:self Options:nil]lastobject]; } [Button.first addtarget:self action: @selector (Btnclick:Event:) Forcontrolevents:uicontroleventtouchupinside]; returnbutton;}
The second step: the key code
-(void) Btnclick: (ID) senderEvent:(ID)Event{ //get a collection of touch points to judge multi-touch eventsNsset *touches=[EventAlltouches]; //two words is to save the touch start positionUitouch *touch=[touches anyobject]; Cgpoint cureenttouchposition=[Touch locationInView:self.table]; //get the Indexpath in the cellNsindexpath *indexpath=[self.table indexpathforrowatpoint:cureenttouchposition]; NSLog (@"Section ----%i,----row---%i", Indexpath.section,indexpath.row);}
Key points of the comments have, simple function to achieve!!!!
IOS gets both the section and row values in UITableViewCell