uiactionsheet
unrecognized selector sent to instance UIActionSheet
I receive the following error when trying to show an ActionSheet... 2012-11-16 04:07:03.878 MKS WebTech[814:c07] -[mksWorkOrderViewController _presentActionSheet:asPopoverFromBarButtonItem:orFromRect:inView:withPreferredArrowDirections:passthroughViews:backgroundStyle:animated:]: unrecognized selector sent to instance 0x75a5950 - (IBAction)ActionClick:(id)sender { popupSheet = [[UIActionSheet alloc] init]; [popupSheet setDelegate:self]; [popupSheet addButtonWithTitle:#"Contact List"]; [popupSheet addButtonWithTitle:#"Zone Descriptions"]; [popupSheet addButtonWithTitle:#"Zone Testing"]; [popupSheet addButtonWithTitle:#"Panels"]; [popupSheet addButtonWithTitle:#"Time Sheet"]; [popupSheet addButtonWithTitle:#"Inventory"]; [popupSheet addButtonWithTitle:#"Other Appt."]; [popupSheet addButtonWithTitle:#"Alarm History"]; [popupSheet addButtonWithTitle:#"Service History"]; [popupSheet addButtonWithTitle:#"Complete"]; [popupSheet addButtonWithTitle:#"Cancel"]; [popupSheet setCancelButtonIndex:10]; // Prepare your action sheet [popupSheet showFromBarButtonItem:bntAction animated:NO]; [popupSheet release]; } The error happen "showFromBarButtonItem:bntAction" I also tried with sender but same result also the canPerformAction fires with no problem... - (BOOL)canPerformAction:(SEL)action withSender:(id)sender { return YES; }
I had this problem once, it's not the same case, but for me, this worked: Go to Interface Builder Check ALL objects, the problem for me was that I connected an object to a variable that I later deleted, so it didn't exist. Conclusion: I had connected an object to a variable that doesn't exist. Otherwise, the code looks fine :)
For anyone else who runs into this in the future (as I just did): the problem is that UIActionSheet walks up the responder chain calling -canPerformAction:#selector(_presentActionSheet:asPopover... etc etc) on each. So since the controller incorrectly responds YES, the UIActionSheet goes ahead and tries to call that method, an implementation doesn't exist, and you hit the error. The correct fix is to reimplement your -canPerformAction:withSender: to only return YES to things you actually handle.
Related Links
Attachment action sheet hidden behind keyboard in iOS 9
Use of Actionsheet in Ionic 2
Disable WKActionSheet on WKWebView
Action sheet programatically [closed]
unrecognized selector sent to instance UIActionSheet
Using Viewcontroller to control tabbarController
ShareKit 2.0: how to add a custom NON-SHARE item in action sheet?
Fire UIActionSheet in ViewDidLoad first load only
Setting bounds for UIActionSheet?