0

当我想更改它的形状或颜色时,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'

4

1 回答 1

0

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

(BIDQuartzFunView *)self.view

尝试这个:

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

然后它应该响应 setShapeView:

[funview setShapeView:[control selectedSegmentIndex];

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

[self.view addSubview:funView];
于 2013-05-15T03:23:59.643 回答