我正在开发像Instagram这样的应用程序。
我有cellForRowAtIndexPath
的代码,每次为解开按钮创建对象并且它是自动释放。这个按钮显示用户名,它可能是1,2,3,4,5,..总和用户一样。因为我创建UIButton
取决于喜欢cout。
我没有使用ARC
。
但是当setColour时它有时会崩溃(不是每个时间)。
我已启用NSZombie
并且一直说:
[UIDeviceRGBColor set]:发送到解除分配的实例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];
我也看到以下链接
UISwitch setThumbTintColor causing crash (iOS 6 only)?
1 out of 4 colors return errors
iOS App crashes when using colorWithRed:green:blue:alpha
和其他..但所有人都说全球Objct。不是本地对象。我怎么能解决它。 谢谢
答案 0 :(得分:2)
试试这段代码......
[btnLikeUserName setTitleColor:[UIColor colorWithRed:((float) 50 / 255.0f)
green:((float) 79 / 255.0f)
blue:((float) 133 / 255.0f)
alpha:1.0f] forState:UIControlStateNormal];
或您也可以将UIColor
设置为如下。
[btnLikeUserName setTitleColor:[UIColor colorWithRed:50.0f/255.0f green:79.0f/255.0f blue:133.0f/255.0f alpha:1.0] forState:UIControlStateNormal];
在这里你在每个单元格中添加UIButtons
然后尝试定义如下所示,而不是每次都分配和自动释放.....
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
* 更新 : *请参阅我在每个单元格中添加的示例,其中包含多个按钮,如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];