iphone - [UIDeviceRGBColor set]: message sent to deallocated instance -
i developing application instagram. have code cellforrowatindexpath
, every time creates object unbutton , autorelease. button display username , may 1,2,3,4,5,.. total users. there create uibutton
on depend on cout. not using arc
.
but crash (not everytime) when setcolour.
i enabled nszombie
, keeps saying:
[uidevicergbcolor set]: message sent deallocated instance 0x21b526f0
uibutton *btnlikeusername = [[[uibutton alloc] init] autorelease]; [btnlikeusername.titlelabel setfont:[uifont boldsystemfontofsize:12]]; if (posx + size.width > 280) { posy = posy + 22; posx = 18; btnlikeusername.frame = cgrectmake(posx,posy,size.width,size.height); posx = posx + size.width + 5; } else { btnlikeusername.frame = cgrectmake(posx,posy,size.width,size.height); posx = posx + size.width + 5; } btnlikeusername.tag = shareobju.userid; [btnlikeusername settitle:text forstate:uicontrolstatenormal]; [btnlikeusername settitlecolor:[uicolor colorwithred:50/255.0 green:79/255.0 blue:133/255.0 alpha:1.0] forstate:uicontrolstatenormal]; ////hear crash [btnlikeusername addtarget:self action:@selector(btnlikeusernameclick:) forcontrolevents:uicontroleventtouchupinside]; [cell.viewlikecomment addsubview:btnlikeusername];
i see following link
uiswitch setthumbtintcolor causing crash (ios 6 only)?
1 out of 4 colors return errors
ios app crashes when using colorwithred:green:blue:alpha
and other .. says global objct. not local object. how can solved it. thank you
try code...
[btnlikeusername settitlecolor:[uicolor colorwithred:((float) 50 / 255.0f) green:((float) 79 / 255.0f) blue:((float) 133 / 255.0f) alpha:1.0f] forstate:uicontrolstatenormal];
or can set uicolor
bellow.
[btnlikeusername settitlecolor:[uicolor colorwithred:50.0f/255.0f green:79.0f/255.0f blue:133.0f/255.0f alpha:1.0] forstate:uicontrolstatenormal];
and here add uibuttons
in every cell try define bellow not alloc , autorelease everytime .....
uibutton *button = [uibutton buttonwithtype:uibuttontypecustom];
*update:*see example add in every cell multiple button gridview
uibutton *button = [uibutton buttonwithtype:uibuttontypecustom]; button.frame = rect; button.tag = imageindex; [button addtarget:self action:@selector(btntemp_clicked:) forcontrolevents:uicontroleventtouchdown]; [button settitle:[arrtime objectatindex:imageindex] forstate:uicontrolstatenormal]; [button.titlelabel setfont:[uifont fontwithname:@"helvetica-bold" size:12]]; //[button settitlecolor:[uicolor colorwithpatternimage:[uiimage imagenamed:@"circle03.jpg"]] forstate:uicontrolstatenormal ]; [button settitlecolor:[uicolor colorwithred:50.0f/255.0f green:79.0f/255.0f blue:133.0f/255.0f alpha:1.0] forstate:uicontrolstatehighlighted ]; [button setneedsdisplay]; [gridcell.contentview addsubview:button];