【发布时间】:2015-09-21 21:49:08
【问题描述】:
2015-07-03 22:13:37.230 Hyponerd[64413:2308636] 加载了它的视图 2015-07-03 22:13:39.860 Hyponerd[64413:2308636]-[BNRHyposisView MySegmentedControlAction:]:无法识别的选择器发送到实例 0x7fcbd27623b0 2015-07-03 22:13:39.866 Hyponerd[64413:2308636] * 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[BNRHyposisView MySegmentedControlAction:]:无法识别的选择器发送到实例 0x7fcbd27623b0” * 首先抛出调用栈:
这是什么意思?我一直在尝试解决这四个小时 我的代码是:
@implementation BNRHyponosisViewController
-(void)loadView {
//Create a view
CGRect frame = [UIScreen mainScreen].bounds;
_backgroundView = [[BNRHyposisView alloc]initWithFrame:frame];
NSArray *colors = @[@"Red", @"Blue", @"Green"];
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc]initWithItems:colors];
segmentedControl.frame = CGRectMake(40, 200, 250, 50);
segmentedControl.backgroundColor = [UIColor blackColor];
segmentedControl.selectedSegmentIndex = 1;
[_backgroundView addSubview:segmentedControl];
[segmentedControl addTarget:_backgroundView action:@selector(MySegmentedControlAction:) forControlEvents:UIControlEventValueChanged];
self.view = _backgroundView;
}
-(instancetype)initWithNibName:(NSString *)nibNameOrNil bundle: (NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.tabBarItem.title = @"Hypnotize";
UIImage *image = [UIImage imageNamed:@"Hypno.png"];
self.tabBarItem.image = image;
} return self;
}
-(void)viewDidLoad {
[super viewDidLoad];
NSLog(@"loaded its view");
}
-(void)MySegmentedControlAction:(UISegmentedControl*)segment
{
if (segment.selectedSegmentIndex == 0) {
[_backgroundView setCircleColor:[UIColor redColor]];
} else if (segment.selectedSegmentIndex == 1) {
[_backgroundView setCircleColor:[UIColor greenColor]];
} else if (segment.selectedSegmentIndex == 2) {
[_backgroundView setCircleColor:[UIColor blueColor]];
}
}
@end
【问题讨论】:
标签: objective-c exception error-handling