我的UIButtons变成了UIImageviews

时间:2014-09-20 08:43:09

标签: ios uibutton

我有UIScrollview个按钮,每次点击其中一个按钮,我都会更改背景,图像和标签。它工作正常,直到今天它崩溃,它说无法识别的选择器。当我NSLog我的按钮时,我可以第二次看到按钮不再是UIImageViews

怎么会发生这种情况?

代码非常大但这是问题部分

for (int j = 100; j<[[Utils categoriesName] count]+100; j++)
{
    UIButton *clickedButton = (UIButton *)[self.view viewWithTag:j];
    UILabel *clickedLabel = (UILabel *)[self.view viewWithTag:j+100];
    NSLog(@"%@  \n%@\n\n",clicked Button, clickedLabel);
    [clickedButton setImage:[UIImage imageNamed:[[Utils categoriesIconLight] objectAtIndex:(j-100)]] forState:UIControlStateNormal];
    [clickedButton setImage:[UIImage imageNamed:[[Utils categoriesIconLight] objectAtIndex:(j-100)]] forState:UIControlStateHighlighted];
    [clickedLabel setTextColor:[UIColor whiteColor]];
    [clickedButton setBackgroundImage:[UIImage imageNamed:@"category-button-background"] forState:UIControlStateNormal];
    [clickedButton setBackgroundImage:[UIImage imageNamed:@"category-button-background-selected"] forState:UIControlStateHighlighted];
    [clickedButton setBackgroundColor:[UIColor clearColor]];
}

第二次运行此循环时clickedButton和clickedLabel都是UIImageViews

这是第一个循环上的第一个按钮和标签

<UIButton: 0xd981640; frame = (0 0; 269 46); opaque = NO; tag = 100; layer = <CALayer: 0xd981730>>  
<UILabel: 0xd9861c0; frame = (47 10; 222 22); text = 'Android'; userInteractionEnabled = NO; tag = 200; layer = <CALayer: 0xd985f10>>

和第二个循环

 <UIImageView: 0xd983070; frame = (0 0; 160 120); clipsToBounds = YES; opaque = NO; tag = 100; gestureRecognizers = <NSArray: 0xd974eb0>; layer = <CALayer: 0xd988660>>  
 <UIImageView: 0xd98c0a0; frame = (0 0; 160 120); clipsToBounds = YES; opaque = NO; tag = 200; gestureRecognizers = <NSArray: 0xd98a5b0>; layer = <CALayer: 0xd98a3a0>>

0 个答案:

没有答案