修改NSMutablearray中的按钮属性?

时间:2013-09-25 12:37:21

标签: ios objective-c arrays

如何更改NSMutable Array中按钮(在索引处)的属性?

这是我的代码:

                [btnRange addObject:btn12Out];
                [btnRange addObject:btn13Out];
                [btnRange addObject:btn14Out];
                [btnRange addObject:btn17Out];
                [btnRange addObject:btn18Out];
                [btnRange addObject:btn19Out];
                //start ordering   

                for (NSInteger i=0; i <= 5; i++) {
                    nxt = btnRange[arc4random_uniform([btnRange count])];
                    btnOrder[i] = nxt;                    
                    [btnRange removeObject:nxt];
                }


                //skipping down


    if ([status isEqualToString:@"Computer"]) {
        switch (level) {
            case 1:
                //here's where I want to edit the properties 
                //of a buttonn in the array (at a certain index)
                nxt = btnOrder[current];
                UIButton *newbutton = nxt;
                [newbutton setBackgroundImage:@"buttonmem3" forstate:UIControlStateNormal];


                //Fin

但是xcode喜欢说“newbutton”没有@interfae

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

<强>校正

UIButton方法setBackgroundImage:forState:接受UIImage作为参数而非NSString。更改以下行。

[newbutton setBackgroundImage:[UIImage imageNamed:@"buttonmem3"] forState:UIControlStateNormal];

假设您的应用包中添加了“buttonmem3.png”。