iphone - How to increase the Label value separately in each row,table contains so many Sections -


i have uitableview number of sections , rows.

when user selects cell, how perform actions of plus , minus buttons in viewcontroller? mean increase label value each row separately?

enter image description here

- (nsarray *)sectionindextitlesfortableview:(uitableview *)tableview {     nsarray *tobereturned = [nsarray arraywitharray:                              [@"a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z"                               componentsseparatedbystring:@"|"]];      return tobereturned; } 

//cell row

- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {     static nsstring *myidentifier= @"myidentifier";     locationscustomcell *cell= (locationscustomcell *)[tableview dequeuereusablecellwithidentifier:myidentifier];     if(cell==nil)     {         [[nsbundle mainbundle] loadnibnamed:@"locationscustomcell" owner:self options:nil];         cell=locationcustomcell;     }     @try     {         if(indexpath.section<=[arrayofcharacters count])         {             nsstring *sortedstr =[[objectsforcharacters objectforkey:[arrayofcharacters objectatindex:indexpath.section]] objectatindex:indexpath.row];              if([sortedstr iskindofclass:[nsnull class]])             {                 cell.locationnamelabel.text=@"";             }             else             {                 cell.locationnamelabel.text=sortedstr;                 cell.locationnamelabel.textcolor=[uicolor blackcolor];             }         }     }     @catch (nsexception *exception)     {      }     sectionno=indexpath.section;       cell.plusbutn.tag  = sectionno*100+indexpath.row;      cell.minusbutn.tag = sectionno*100+indexpath.row;      cell.locationcountlabel.tag=sectionno*100+indexpath.row;       pluselement=[indexpath row];    // nsinteger sectionmame=[indexpath section];    // nsinteger rowname =[indexpath row];      minuselement=[indexpath row];      countlabelelement=[indexpath row];      [cell.plusbutn addtarget:self action:@selector(plusbutnpressed:) forcontrolevents:uicontroleventvaluechanged];      //[cell.plusbutn addtarget: self                       // action: @selector(buttonpressed:withevent:)              //forcontrolevents: uicontroleventtouchupinside];     // [cell.minusbutn addtarget:self action:@selector(minusbutnpressed:) forcontrolevents:uicontroleventvaluechanged];      [cell setselectionstyle:uitableviewcellselectionstylenone];      return cell; }   -(ibaction)plusbutnpressed:(id)sender {     nslog(@"selectedsection number/plusbutn is--%d",sectionnumber);     locationscustomcell *cell=(locationscustomcell *)[self.locationstablevw cellforrowatindexpath:[nsindexpath indexpathforrow:pluselement insection:sectionnumber]];     cell.plusbutn=(uibutton *)sender;     if (cell.plusbutn)     {         countvalue++;         nsstring *valuestr= [nsstring stringwithformat:@"%d",countvalue];         cell.locationcountlabel.text=valuestr;     } }  -(ibaction)minusbutnpressed:(id)sender {     nslog(@"selectedsection number/minusbutn is--%d",sectionnumber);     locationscustomcell *cell=(locationscustomcell *)[self.locationstablevw cellforrowatindexpath:[nsindexpath indexpathforrow:minuselement insection:sectionnumber]];     cell.minusbutn=(uibutton *)sender;     if (cell.minusbutn)     {         countvalue--;         nsstring *valuestr= [nsstring stringwithformat:@"%d",countvalue];         cell.locationcountlabel.text=valuestr;     } } 

try it

in cellforrowatindexpath

    [thecell.button addtarget: self                action: @selector(buttonpressed:withevent:)      forcontrolevents: uicontroleventtouchupinside]; 

then event handler this:

      - (void) buttonpressed: (id) sender withevent: (uievent *) event       {           uitouch * touch = [[event touches] anyobject];           cgpoint location = [touch locationinview: self.tableview];           nsindexpath * indexpath = [self.tableview indexpathforrowatpoint: location];             /* indexpath contains index of row containing button */          nsstring *str=[self.tableview cellforrowatindexpath:indexpath].locationcountlabel.text;             int a=[str intvalue];             a=a+1;            [self.tableview cellforrowatindexpath:indexpath].locationcountlabel.text=[nsstring stringwithformat:@"%d",a];        } 

and can done minus, same way decrease value of a.

edit

put line

         [cell.plusbutn addtarget:self action:@selector(plusbutnpressed:) forcontrolevents:uicontroleventvaluechanged]; 

in if (cell==nil) , run code not code.

    if(cell==nil)     {             [[nsbundle mainbundle] loadnibnamed:@"locationscustomcell" owner:self options:nil];             cell=locationcustomcell;             [cell.plusbutn addtarget:self action:@selector(plusbutnpressed:) forcontrolevents:uicontroleventtouchupinside]; /////////this line put here       } 

Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -