iphone - How to access the checkboxes in the Tableview Cell? -
hai,iam printing checkbox every row.but when select checkbox last cell checkbox selecting.below 1 code printing checkboxes , daily,weekly,monthly data.
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *cellidentifier = @"cell"; uitableviewcell *cell = [[uitableviewcell alloc]init]; cell = [self getcellcontentview:cellidentifier]; uilabel *lbltemp1 = (uilabel *)[cell viewwithtag:1]; uilabel *lbltemp2 = (uilabel *)[cell viewwithtag:2]; uilabel *lbltemp3 = (uilabel *)[cell viewwithtag:3]; uilabel *lbltemp4 = (uilabel *)[cell viewwithtag:4]; checkbutton=[uibutton buttonwithtype:uibuttontypecustom]; checkbutton.frame = cgrectmake(5,30, 15, 10); [checkbutton addtarget:self action:@selector(selectcheckbox) forcontrolevents:uicontroleventtouchupinside]; pictureimageview=[[uiimageview alloc]initwithframe:cgrectmake(20, 5, 100, 60)]; //pictureimageview=[[uiimageview alloc]initwithframe:cgrectmake(2, 3, 65, 65)]; [pictureimageview.layer setbordercolor:[[uicolor graycolor] cgcolor]]; [pictureimageview.layer setshadowcolor:[[uicolor graycolor] cgcolor]]; [pictureimageview.layer setmaskstobounds:yes]; [pictureimageview.layer setborderwidth:1.5]; [pictureimageview.layer setcornerradius:5.0]; [pictureimageview.layer setshadowradius:1.0]; [pictureimageview.layer setshadowopacity:3.0]; if(selectedsegment==0) { databasefields=[eventdata objectatindex:indexpath.row]; lbltemp1.text=databasefields.dbtitle; lbltemp2.text=databasefields.dblocation; lbltemp3.text=databasefields.dbdate ; lbltemp4.text=databasefields.dbtime; //nsstring *picturestring=[[nsstring alloc]init]; picturestring=databasefields.dbpicture; checkimage = [uiimage imagenamed:@"checkbox.png"]; [checkbutton setimage:checkimage forstate:uicontrolstatenormal]; pictureimageview.image = [uiimage imagewithcontentsoffile:picturestring]; [cell.contentview addsubview:checkbutton]; [cell.contentview addsubview:pictureimageview]; } else if(selectedsegment==1) { databasefields=[eventdata objectatindex:indexpath.row]; lbltemp1.text=databasefields.dbtitle; lbltemp2.text=databasefields.dblocation; lbltemp3.text=databasefields.dbdate; lbltemp4.text=databasefields.dbtime; picturestring=[[nsstring alloc]init]; picturestring=databasefields.dbpicture; checkimage = [uiimage imagenamed:@"checkbox.png"]; pictureimageview.image = [uiimage imagewithcontentsoffile:picturestring]; [cell.contentview addsubview:checkbutton]; [cell.contentview addsubview:pictureimageview]; } else if(selectedsegment==2) { databasefields=[eventdata objectatindex:indexpath.row]; lbltemp1.text=databasefields.dbtitle; lbltemp2.text=databasefields.dblocation; lbltemp3.text=databasefields.dbdate; lbltemp4.text=databasefields.dbtime; picturestring=[[nsstring alloc]init]; picturestring=databasefields.dbpicture; checkimage = [uiimage imagenamed:@"checkbox.png"]; [checkbutton setimage:checkimage forstate:uicontrolstatenormal]; pictureimageview.image = [uiimage imagewithcontentsoffile:picturestring]; [cell.contentview addsubview:checkbutton]; [cell.contentview addsubview:pictureimageview]; } // configure cell... return cell; } -(void) selectcheckbox { if (checkboxselected == 0){ [checkbutton setselected:yes]; checkimage = [uiimage imagenamed:@"checkbox-on.png"]; [checkbutton setimage:checkimage forstate:uicontrolstatenormal]; checkboxselected = 1; } else { [checkbutton setselected:no]; checkimage = [uiimage imagenamed:@"checkbox.png"]; [checkbutton setimage:checkimage forstate:uicontrolstatenormal]; checkboxselected = 0; } ; }
please give me solution selecting every checkbox
please read table view programming guide learn cells. in case, looks checkbutton
instance variable of table delegate, , that's you're modifying in -selectcheckbox
method. however, variable points button in cell created recently. if want operate on particular cell, should first cell row, , find check box button. 1 way set tag
property particular value when set cell. can ask cell subview has tag.
Comments
Post a Comment