ios - Detect which button was clicked in a grouped UITableView -
i have grouped uitableview (this 1 has 4 sections) , several rows each. have programatically created 2 buttons in each of cells.
this how creating uitableviewcell
. in code, trying detect indexpath.row , indexpath.section of button pressed , pass method. how able ?
-(uitableviewcell*)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath{ static nsstring *cellid = @"cell"; uitableviewcell *cell ;//= [tableview dequeuereusablecellwithidentifier:nil]; if (cell == nil) { cell = [[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellid]; } nsstring *doctitle = [currentdocument objectforkey:@"displayname"]; uiview *cellview = [[uiview alloc] initwithframe:cgrectmake(cell.contentview.frame.origin.x+5, cell.contentview.frame.origin.y, cell.contentview.frame.size.width, cell.contentview.frame.size.height)]; uilabel *celltitle = [[uilabel alloc] initwithframe:cgrectmake(cellview.frame.origin.x + 5, cellview.frame.origin.y + 5, cellview.frame.size.width - 10, 25)]; celltitle.backgroundcolor = [uicolor clearcolor]; celltitle.text = doctitle; [cellview addsubview:celltitle]; [cell.contentview addsubview:cellview]; uibutton *viewdocumentbutton = [uibutton buttonwithtype:uibuttontyperoundedrect]; [viewdocumentbutton settitle:@"view online" forstate:uicontrolstatenormal]; viewdocumentbutton.frame = cgrectmake(cellview.frame.origin.x + 5, celltitle.frame.origin.y + celltitle.frame.size.height + 5, 150, 35); [viewdocumentbutton addtarget:self action:@selector(opendocumentbuttonpressedmethod:) forcontrolevents:uicontroleventtouchdown]; [viewdocumentbutton settag:indexpath.row]; [cell.contentview addsubview:viewdocumentbutton]; uibutton *downloaddocumentbutton = [uibutton buttonwithtype:uibuttontyperoundedrect]; [downloaddocumentbutton settitle:@"download document" forstate:uicontrolstatenormal]; downloaddocumentbutton.frame = cgrectmake(cellview.frame.origin.x + 5, viewdocumentbutton.frame.origin.y + viewdocumentbutton.frame.size.height + 5, 150, 35); [downloaddocumentbutton addtarget:self action:@selector(opendocumentbuttonpressedmethod:) forcontrolevents:uicontroleventtouchdown]; [downloaddocumentbutton settag:indexpath.row]; [cell.contentview addsubview:downloaddocumentbutton]; cell.selectionstyle = uitableviewcellselectionstylenone; return cell; }
additionally, could...
- (ibaction)opendocumentbuttonpressedmethod:(id)sender { uibutton *button = (uibutton *)sender; uiview *contentview = button.superview; uitableviewcell *cell = (uitableviewcell *)contentview.superview; nsindexpath *indexpath = [self.tableview indexpathforcell:cell]; // indexpath }
and if wanted use same method handle both button events, use tag on button distinguish between 2 buttons.
if (button.tag == 1) { // indexpath view related } else { // indexpath download related }
Comments
Post a Comment