ios - Count of checkboxes is not showing properly -
i making app in using in form of checkboxes. want show count of checkboxes in text label trying not find possible solution.. here project link https://www.dropbox.com/s/iu8fdz4y0ps4xye/checkboxwithtableview%202.zip?dl=0 kindly review it.. below sample code
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *tableviewidentifier = @"cell"; tablecelltableviewcell *cell= [self.tblvie dequeuereusablecellwithidentifier:tableviewidentifier]; if(cell==nil) { cell = [[tablecelltableviewcell alloc] initwithstyle:uitableviewcellstylesubtitle reuseidentifier:tableviewidentifier]; } cell.lblimage.layer.cornerradius=3.0f; cell.lblimage.layer.borderwidth=1.0f; if ([self.checkimagearray containsobject:[self.lblarray objectatindex:indexpath.row]]) { [cell.buttoncheckbox setimage:[uiimage imagenamed:@"checkbox.png"] forstate:uicontrolstatenormal]; // [cell.buttoncheckbox setimage:[uiimage imagenamed:@"checkboxmarked.png"] forstate:uicontrolstatenormal]; } else { //[cell.buttoncheckbox setimage:[uiimage imagenamed:@"checkbox.png"] forstate:uicontrolstatenormal]; [cell.buttoncheckbox setimage:[uiimage imagenamed:@"checkboxmarked.png"] forstate:uicontrolstatenormal]; } cell.buttoncheckbox.tag=indexpath.row; [cell.buttoncheckbox addtarget:self action:@selector(checkbutton:) forcontrolevents:uicontroleventtouchupinside]; cell.lbltext.text=[self.lblarray objectatindex:indexpath.row]; return cell; } -(ibaction)checkbutton:(uibutton *)sender { cgpoint buttonposition = [sender convertpoint:cgpointzero toview:self.tblvie]; nsindexpath *indexpath = [self.tblvie indexpathforrowatpoint:buttonposition]; if ([self.checkimagearray containsobject:[self.lblarray objectatindex:indexpath.row]]) { [self.checkimagearray removeobject:[self.lblarray objectatindex:indexpath.row]]; self.titlelabel.text=@""; } else { [self.checkimagearray addobject:[self.lblarray objectatindex:indexpath.row]]; nsarray *arr=[self.tblvie indexpathsforselectedrows];// here declaring array array coming nil self.titlelabel.text=[self.lblarray objectatindex:indexpath.row]; } [self.tblvie reloadrowsatindexpaths:[nsarray arraywithobject:indexpath] withrowanimation: uitableviewrowanimationfade]; }
add int variable in .h int checkboxescount;
initialize in viewdidload checkboxescount = 0;
than update method below
-(ibaction)checkbutton:(uibutton *)sender { cgpoint buttonposition = [sender convertpoint:cgpointzero toview:self.tblvie]; nsindexpath *indexpath = [self.tblvie indexpathforrowatpoint:buttonposition]; if ([self.checkimagearray containsobject:[self.lblarray objectatindex:indexpath.row]]) { [self.checkimagearray removeobject:[self.lblarray objectatindex:indexpath.row]]; checkboxescount = checkboxescount - 1; self.titlelabel.text=[nsstring stringwithformat:@"count %d",checkboxescount]; } else { [self.checkimagearray addobject:[self.lblarray objectatindex:indexpath.row]]; // self.titlelabel.text=[self.lblarray objectatindex:sender.tag]; checkboxescount = checkboxescount + 1; self.titlelabel.text=[nsstring stringwithformat:@"count %d",checkboxescount]; } [self.tblvie reloadrowsatindexpaths:[nsarray arraywithobject:indexpath] withrowanimation: uitableviewrowanimationfade]; }
problem resolved. tested same on end.
Comments
Post a Comment