中的選擇器我正在使用下面定義的類來保存選擇器和選擇器。在選擇器的didSelectRow方法中,我想執行選擇器。但是,當我使用選擇器來更改行時,我總是收到「無法識別的選擇器發送到實例」異常。執行存儲在類
我已經嘗試將選擇器的聲明更改爲「SEL * theSelector」,但是這不會帶來任何快樂,因爲performSelector被調用時該選擇器爲NULL。
任何修復/想法將不勝感激。先謝謝了。
類與選擇:
@implementation ClassA{
UIPickerView *thePicker;
SEL theSelector;
}
-(id)initWithView:(UIView*)theView{
thePicker = [[UIPickerView alloc] init];
thePicker.showsSelectionIndicator = YES;
thePicker.delegate = self;
thePicker.dataSource = self;
[theView addSubview:thePicker];
theSelector = NULL;
}
-(void)setSelector:(SEL)selector{
theSelector = selector;
}
-(void)performTheSelector{
if (theSelector != NULL) {
[self performSelector:theSelector onThread:[NSThread currentThread] withObject:self waitUntilDone:YES];
}
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent: (NSInteger)component {
[self performTheSelector];
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
return 10;
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
return @"Some Row";
}
類創建ClassA和組選擇的實例:
@implementation ClassB{
}
-(void)initWithView:(UIView*)theView{
ClassA *objectA = [ClassA alloc] initWithView:theView]];
[objectA setSelector:@selector(theSelectorMethod:)];
}
-(IBAction)theSelectorMethod:(id)sender{
//do something
}
它不應該被聲明爲'SEL *'。錯誤消息中無法識別的選擇器是什麼?在伊娃裏還有別的什麼?你爲什麼做這個? (注意,你不需要初始化ivars爲0 - 這是通過'alloc'完成的,而且你的'init'需要'return self'。) –
在行上提出異常: [self performSelector :theSelector onThread:[NSThread currentThread] withObject:self waitUntilDone:YES]; – AndyW
但是錯誤信息的全文是什麼?什麼是無法識別的選擇器本身? –