0

我正在使用 MHRotaryKnob 类并且无法配置它,以便多个插座具有相同的默认设置。使用 IBOutlet 让它与一个实例一起工作是没有问题的,但现在它正在寻找 NSArray 中的 MHRotaryKnob 类的属性。

我究竟如何在实现中定义旋转旋钮,以便将设置中继到连接到 IBOutletCollection 的所有控件?实现中的属性在 MHRotaryKnob.m 中定义,但现在编译器正在 NSArray 中查找它。

视图控制器.h

#import <UIKit/UIKit.h>
#import "MHRotaryKnob.h"

@interface CBViewController : UIViewController

@property (nonatomic, retain) IBOutletCollection (MHRotaryKnob) NSArray *rotaryKnob;

视图控制器.m

#import "ViewController.h"
#import "MHRotaryKnob.h"


@implementation CBViewController;

@synthesize rotaryKnob;


- (void)viewDidLoad
{
[super viewDidLoad];

rotaryKnob.interactionStyle = MHRotaryKnobInteractionStyleSliderVertical;
rotaryKnob.scalingFactor = 1.5f;
rotaryKnob.defaultValue = rotaryKnob.value;
rotaryKnob.resetsToDefault = YES;
rotaryKnob.backgroundColor = [UIColor whiteColor];
rotaryKnob.backgroundImage = [UIImage imageNamed:@"knob_passive.png"];
[rotaryKnob setKnobImage:[UIImage imageNamed:@"knob_passive.png"] forState:UIControlStateNormal];
[rotaryKnob setKnobImage:[UIImage imageNamed:@"knob_highlighted.png"] forState:UIControlStateHighlighted];
[rotaryKnob setKnobImage:[UIImage imageNamed:@"Knob Disabled.png"] forState:UIControlStateDisabled];
rotaryKnob.knobImageCenter = CGPointMake(35.0f, 32.0f);
[rotaryKnob addTarget:self action:@selector(rotaryKnobDidChange) forControlEvents:UIControlEventValueChanged];
4

1 回答 1

0

AnIBOutletCollection是一个集合,因此NSArray在这种情况下它由 an 支持。

因此,将 ivar 重命名为rotaryKnobs以明确这一事实可能会有所帮助,然后像这样使用它

for (MHRotaryKnob *rotaryKnob in self.rotaryKnobs) {
    rotaryKnob.interactionStyle = MHRotaryKnobInteractionStyleSliderVertical;
    rotaryKnob.scalingFactor    = 1.5f;
    rotaryKnob.defaultValue     = rotaryKnob.value;
    rotaryKnob.resetsToDefault  = YES;
    rotaryKnob.backgroundColor  = [UIColor whiteColor];
    rotaryKnob.backgroundImage  = [UIImage imageNamed:@"knob_passive.png"];
    rotaryKnob.knobImageCenter  = CGPointMake(35.0f, 32.0f);
    [rotaryKnob setKnobImage:[UIImage imageNamed:@"knob_passive.png"]     forState:UIControlStateNormal];
    [rotaryKnob setKnobImage:[UIImage imageNamed:@"knob_highlighted.png"] forState:UIControlStateHighlighted];
    [rotaryKnob setKnobImage:[UIImage imageNamed:@"Knob Disabled.png"]    forState:UIControlStateDisabled];
    [rotaryKnob addTarget:self action:@selector(rotaryKnobDidChange) forControlEvents:UIControlEventValueChanged];
}
于 2012-05-13T15:44:53.180 回答