I am developing application like Instagram.
I have code for cellForRowAtIndexPath
, every time it creates object for unbutton and it is autorelease. this button display username and it may be 1,2,3,4,5,.. total like users. there for i create UIButton
on depend on like cout.
I am not using ARC
.
but it crash sometimes (Not everyTime) when setColour.
I enabled NSZombie
and it keeps saying:
[UIDeviceRGBColor set]: message sent to 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 is crash
[btnLikeUserName addTarget:self action:@selector(btnLikeUserNameClick:) forControlEvents:UIControlEventTouchUpInside];
[cell.viewLikeComment addSubview:btnLikeUserName];
i also 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 .. but all says for global Objct. not local object. how can i solved it. Thank You
try this 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 Also you can set UIColor
like 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 you Add UIButtons
in every cell then try to define like bellow not alloc and autorelease everytime .....
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
*UPDATE:*See the example which i add in my every cell with multiple button like 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];