段控制器选择器错误?

时间:2013-05-15 03:07:22

标签: objective-c

当我想改变它抛出错误的形状或颜色时,iphone上的段控制器有问题

  #import "BIDViewController.h"
#import "BIDQuartzFunView.h"
#import "BIDConstants.h"


@interface BIDViewController ()

@end

@implementation BIDViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)changeColor:(id)sender {
    UISegmentedControl *control = sender;
    NSInteger index = [control selectedSegmentIndex];

    BIDQuartzFunView *funView = (BIDQuartzFunView *)self.view;

    switch (index) {
        case kRedColorTab:
            funView.currentColor = [UIColor redColor];
            funView.useRandomColor = NO;
            break;
        case kBlueColorTab:
            funView.currentColor = [UIColor blueColor];
            funView.useRandomColor = NO;
            break;
        case kYellowColorTab:
            funView.currentColor = [UIColor yellowColor];
            funView.useRandomColor = NO;
            break;
        case kGreenColorTab:
            funView.currentColor = [UIColor greenColor];
            funView.useRandomColor = NO;
            break;
        case kRandomColorTab:
            funView.useRandomColor = YES;
            break;
        default:
            break;
    }
}

- (IBAction)changeShape:(id)sender {
    UISegmentedControl *control = sender;
    [(BIDQuartzFunView *)self.view setShapeType:[control selectedSegmentIndex]];
    if ([control selectedSegmentIndex] == kImageShape)
        _colorControl.hidden = YES;
    else
        _colorControl.hidden = NO;
}

@end

错误:

  

- [UIView setShapeType:]:无法识别的选择器发送到实例0x767a0a0   2013-05-14 22:42:15.836 QuartzFun [1014:c07] * 由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:' - [UIView setShapeType:]:无法识别的选择器发送到实例0x767a0a0 “

1 个答案:

答案 0 :(得分:0)

我猜你没有正确初始化BIDQuartzFunView,而不是:

(BIDQuartzFunView *)self.view

试试这个:

BIDQuartzFunView *funView = [[BIDQuartzFunView alloc] initWithFrame:self.view.frame]];

然后它应该响应setShapeView:

[funview setShapeView:[control selectedSegmentIndex];

另外不要忘记将BIDQuartzFunView添加到视图中:

[self.view addSubview:funView];