IBOutlet的UIButtonCollection不会突出显示

时间:2012-09-08 16:53:29

标签: ios5 uibutton permanent iboutletcollection setstate

我有一个UIButtons的IBOutletCollection:

@property (nonatomic, retain) IBOutletCollection(UIButton) NSMutableArray *Buttons;

使用ibaction我会在触地事件后永久更改突出显示的状态。

这个问题与此非常相似: IBOutletCollection of UIButtons - changing selected state of buttons

...但是使用for循环按钮不会改变。

我也从这里尝试了perfomselector方法:Keep iPhone UIButton Highlighted

但它不起作用。

现在我的代码:

-(IBAction)toggleButtons:(id)sender
{
    NSUInteger Index = [button tag];
    [[Buttons objectAtIndex:Index] setHighlighted:YES];
}

如果我改变第四行:

    [[Buttons objectAtIndex:3] setHighlighted:YES];

它适用于我的集合中的第四个元素......但不适用于索引变量....

问候,phil

更新

SelectionViewController.h

#import <UIKit/UIKit.h>

@interface SelectionViewController : UIViewController

@property (nonatomic, retain) IBOutletCollection(UIButton) NSMutableArray *Buttons;

- (IBAction)toggleButtons:(id)sender;

@end

SelectionViewController.m

#import "SelectionViewController.h"

@interface SelectionViewController ()

@end

@implementation SelectionViewController

@synthesize Buttons;


-(IBAction)toggleButtons:(id)sender
{
    UIButton *button = sender;
    NSUInteger Index = [button tag];
    [self performSelector:@selector(doHighlight:) withObject:sender afterDelay:0];

    [[Buttons objectAtIndex:Index] setHighlighted:YES];
}
- (void)doHighlight:(UIButton *)b {
    [b setHighlighted:YES];
}

XIB File

Okey Update 2:

现在我已将我的按钮声明为正常的IBOutlet,但这不起作用:

-(IBAction)toggleButtons:(id)sender
{
    UIButton *button = sender;

    [button setHighlighted:YES];
}

但如果改变它:

-(IBAction)toggleButtons:(id)sender
{    
    [myOutletButton setHighlighted:YES]; //Normal Outlet 
}

它有效......

但为什么发件人无法做到?

问候!

更新3

这也有效:

for(id button in self.view.subviews)
{
    [button setHighlighted:YES];

}

如果将选择器中的延迟时间更改为1,则状态将突出显示。我正在使用“触地”事件......我想在我触摸后按钮变为旧状态。哪个事件是对的?

1 个答案:

答案 0 :(得分:0)

鉴于您的示例使用特定的整数,问题可能是没有为每个按钮正确设置标记属性。如果按钮是在界面构建器中创建的,则每个按钮的默认标记值为0.要检查此项,请单击按钮,然后在“属性”检查器中,向下滚动到“查看”,并查看在< em>标记字段

相关问题