iphone - on scrolling the buttons changes its image in uitableviewcell -


can please tell me how can make buttons in uitableview custom cell different images , action.i have tried this. adding button image , action according values in dictionary,it works first time after scrolling ,the button images changes.

- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath{   {      static nsstring *cellidentifier = @"mediapickercustomcell";      mediapickercustomcell *customcell = (mediapickercustomcell *)[tableview dequeuereusablecellwithidentifier:cellidentifier forindexpath:indexpath];       if(customcell == nil){      }      [customcell._titlelabel  setlinebreakmode:uilinebreakmodewordwrap];     [customcell._titlelabel setminimumfontsize:font_size];     [customcell._titlelabel setnumberoflines:0];     [customcell._titlelabel setfont:[uifont systemfontofsize:font_size]];     [customcell._titlelabel settag:1];        nsstring *text = [eventsarray objectatindex:[indexpath row]];      cgsize constraint = cgsizemake(cell_content_width - (cell_content_margin * 2), 20000.0f);      cgsize size = [text sizewithfont:[uifont systemfontofsize:font_size] constrainedtosize:constraint linebreakmode:uilinebreakmodewordwrap];      [customcell._titlelabel setframe:cgrectmake(cell_content_margin, cell_content_margin, cell_content_width - (cell_content_margin * 2), max(size.height, 44.0f))];     customcell._titlelabel.attributedtext=[attributedarrayevents objectatindex:indexpath.row];         cgfloat aheight = [tableview rectforrowatindexpath:indexpath].size.height;      cgrect frame= customcell.priorview.frame;     frame.size.height=aheight;     [customcell.priorview setframe:frame];     //code setframe of btn register     cgfloat aheight1;      cgrect frame1= customcell._titlelabel.frame;     aheight1=frame1.size.height+frame1.origin.y-40;     cgrect frame2= customcell.addeventbtn.frame;     frame2.origin.y=aheight1;     [customcell.addeventbtn setframe:frame2];     [customcell.addeventbtn sethidden:no];     if([[[dataeventarray objectatindex:indexpath.row]objectforkey:@"mandatory"]isequaltostring:@"1"]){           [customcell.addeventbtn setimage:[uiimage imagenamed:@"registered.png"] forstate:uicontrolstatenormal];         [customcell.addeventbtn setuserinteractionenabled:no];     }     else if ([[[dataeventarray objectatindex:indexpath.row]objectforkey:@"mandatory"]isequaltostring:@"0"]){         [customcell.addeventbtn addtarget:self action:@selector(addeventtocaendar) forcontrolevents:uicontroleventtouchupinside];          [customcell.addeventbtn setbackgroundimage:[uiimage imagenamed:@"register_btn.png"] forstate:uicontrolstatenormal];         [customcell.addeventbtn settitle:@"register" forstate:uicontrolstatenormal];         [customcell.addeventbtn setuserinteractionenabled:yes];      }       if([[[dataeventarray objectatindex:indexpath.row] objectforkey:@"priority"] isequaltostring:@"1"]){          customcell.priorview.backgroundcolor=[uicolor colorwithred:255/255.0 green:35/255.0 blue:35/255.0 alpha:1.0];      }      else if([[[dataeventarray objectatindex:indexpath.row] objectforkey:@"priority"] isequaltostring:@"2"]){          customcell.priorview.backgroundcolor=[uicolor colorwithred:237/255.0 green:206/255.0 blue:112/255.0 alpha:1.0];      }      else{         customcell.priorview.backgroundcolor=[uicolor colorwithred:124/255.0 green:197/255.0 blue:118/255.0 alpha:1.0];     }     uiswipegesturerecognizer *gesture = [[uiswipegesturerecognizer alloc] initwithtarget:self action:@selector(swipecalledevents:) ];     customcell.tag=[[[dataeventarray objectatindex:indexpath.row] objectforkey:@"id"] intvalue];      gesture.direction = uiswipegesturerecognizerdirectionright;     [customcell addgesturerecognizer:gesture];     return customcell;  } 

}

try changing:

if(customcell == nil){      } 

to:

if(!customcell)      customcell = [[mediapickercustomcell alloc] initwithstyle:nil reuseidentifier:cellidentifier]; 

that'll correctly allocate cell reuse, stops dequeuing cells in wrong way. initwithstyle can try various types, if it's custom might have created own why left nil in example.


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -