I have create a demo project in which i have add button. On button action i am calling a custom view. On that custom view i have add a picker view, a toolbar and bar button. On action of button i am calling that custom view. I have used this code...
-(IBAction)Picker{
mpv_object = [[MyPickerView alloc] initWithNibName:@"MyPickerView" bundle:nil];
[self.view addSubview:mpv_object];
[mpv_object release];
}
But i give error which i given below...
2011-09-26 09:49:00.236 Web[440:207] -[MyPickerView initWithNibName:bundle:]: unrecognized selector sent to instance 0x4b4dcb0 2011-09-26 09:49:00.287 Web[440:207] *开发者_高级运维 Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MyPickerView initWithNibName:bundle:]: unrecognized selector sent to instance 0x4b4dcb0' * Call stack at first throw: ( 0 CoreFoundation 0x00daebe9 exceptionPreprocess + 185 1 libobjc.A.dylib 0x00f035c2 objc_exception_throw + 47 2 CoreFoundation 0x00db06fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187 3 CoreFoundation 0x00d20366 __forwarding + 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(Internal) _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 ) terminate called after throwing an instance of 'NSException' What is error in this?
It sounds like MyPickerView
is a UIView
subclass. initWithNibName:bundle
is not a method that exists on UIView
subclasses. It is a method that exists on UIViewController
subclasses. That is what the error message means.
unrecognized selector sent to instance
suggests that MyPickerView's superclass doesn't know what initWithNibName:bundle
is, which is because UIView doesn't know that method (it exists in UIViewController
).
Right way to do this would be something like this
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];
精彩评论