我已经创建了一个演示项目,其中我添加了按钮。在按钮操作上,我调用自定义视图。在该自定义视图中,我添加了一个选择器视图,一个工具栏和一个条形按钮。在按钮的操作我调用该自定义视图。我用过这段代码......
-(IBAction)Picker{
mpv_object = [[MyPickerView alloc] initWithNibName:@"MyPickerView" bundle:nil];
[self.view addSubview:mpv_object];
[mpv_object release];
}
但是我给出了以下给出的错误......
2011-09-26 09:49:00.236 Web [440:207] - [MyPickerView initWithNibName:bundle:]:无法识别的选择器发送到实例0x4b4dcb0 2011-09-26 09:49:00.287 Web [440:207] *由于未捕获的异常'NSInvalidArgumentException'终止应用程序,原因:' - [MyPickerView initWithNibName:bundle:]:无法识别的选择器发送到实例0x4b4dcb0' * 在第一次投掷时调用堆栈: ( 0 CoreFoundation 0x00daebe9 exceptionPreprocess + 185 1 libobjc.A.dylib 0x00f035c2 objc_exception_throw + 47 2 CoreFoundation 0x00db06fb - [NSObject(NSObject)doesNotRecognizeSelector:] + 187 3 CoreFoundation 0x00d20366 __ 转发 + 966 4 CoreFoundation 0x00d1ff22 _CF_forwarding_prep_0 + 50 5 Web 0x0000223a - [WebViewController Picker] + 102 6 UIKit 0x002b7a6e - [UIApplication sendAction:to:from:forEvent:] + 119 7 UIKit 0x003461b5 - [UIControl sendAction:to:forEvent:] + 67 8 UIKit 0x00348647 - [UIControl(内部)_sendActionsForEvents:withEvent:] + 527 9 UIKit 0x003471f4 - [UIControl touchesEnded:withEvent:] + 458 10 UIKit 0x002dc0d1 - [UIWindow _sendTouchesForEvent:] + 567 11 UIKit 0x002bd37a - [UIApplication sendEvent:] + 447 12 UIKit 0x002c2732 _UIApplicationHandleEvent + 7576 13 GraphicsServices 0x016e4a36 PurpleEventCallback + 1550 14 CoreFoundation 0x00d90064 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION + 52 15 CoreFoundation 0x00cf06f7 __CFRunLoopDoSource1 + 215 16 CoreFoundation 0x00ced983 __CFRunLoopRun + 979 17 CoreFoundation 0x00ced240 CFRunLoopRunSpecific + 208 18 CoreFoundation 0x00ced161 CFRunLoopRunInMode + 97 19 GraphicsServices 0x016e3268 GSEventRunModal + 217 20 GraphicsServices 0x016e332d GSEventRun + 115 21 UIKit 0x002c642e UIApplicationMain + 1160 22 Web 0x00001f80 main + 102 23 Web 0x00001f11 start + 53 ) 抛出'NSException'实例后终止调用 什么是错误?
答案 0 :(得分:0)
听起来MyPickerView
是UIView
子类。 initWithNibName:bundle
不是UIView
子类上存在的方法。它是UIViewController
子类上存在的方法。这就是错误信息的含义。
答案 1 :(得分:0)
unrecognized selector sent to instance
表明MyPickerView的超类不知道initWithNibName:bundle
是什么,这是因为UIView不知道该方法(它存在于UIViewController
中)。
答案 2 :(得分:0)
这样做的正确方法就是这样
UIView *dpView;
NSArray *nibViews;
nibViews = [[NSBundle mainBundle] loadNibNamed:@"DatePickerSliderViewNew" owner:self options:nil];
dpView = [ nibViews objectAtIndex: 0];
int outside = CGRectGetMaxY(self.view.bounds);
dpView.frame = CGRectMake(0, outside, 320, 260);
[self.view addSubview:dpView];
[UIView beginAnimations:nil context:nil];
dpView.frame = CGRectMake(0, outside - 260, 320, 260);
[UIView commitAnimations];