gpt4 book ai didi

objective-c - ***由于未捕获的异常 'NSInvalidArgumentException'而终止应用程序

转载 作者:行者123 更新时间:2023-12-03 07:59:42 25 4
gpt4 key购买 nike

2015-07-03 22:13:37.230 Hyponerd [64413:2308636]加载了它的 View
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

最佳答案

显然,您是将事件发送到View而不是ViewController,请替换为

[segmentedControl addTarget:_backgroundView action:@selector(MySegmentedControlAction:) forControlEvents:UIControlEventValueChanged];

有了这个
[segmentedControl addTarget:self action:@selector(MySegmentedControlAction:) forControlEvents:UIControlEventValueChanged];

它应该工作

关于objective-c - ***由于未捕获的异常 'NSInvalidArgumentException'而终止应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31217204/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com