0

I already have two ViewControllers, but I wanted to add another...but for some reason I keep getting the error below. There is no code, that I've added, but I am graphically adding an IBAction to go from ViewController to ViewController3.

2016-05-10 12:26:35.259 App-Title[26519:525203] -[ViewController3 setData:]: unrecognized selector sent to instance 0x7f962ae90cf0
2016-05-10 12:26:35.300 App-Title[26519:525203] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ViewController3 setData:]: unrecognized selector sent to instance 0x7f962ae90cf0'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010a8eed85 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x000000010a055deb objc_exception_throw + 48
    2   CoreFoundation                      0x000000010a8f7d3d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
    3   CoreFoundation                      0x000000010a83dcfa ___forwarding___ + 970
    4   CoreFoundation                      0x000000010a83d8a8 _CF_forwarding_prep_0 + 120
    5   App-Title                           0x0000000109b43c85 -[ViewController prepareForSegue:sender:] + 149
    6   UIKit                               0x000000010bab45d5 -[UIStoryboardSegueTemplate _performWithDestinationViewController:sender:] + 369
    7   UIKit                               0x000000010bab4433 -[UIStoryboardSegueTemplate _perform:] + 82
    8   UIKit                               0x000000010bab46f7 -[UIStoryboardSegueTemplate perform:] + 156
    9   UIKit                               0x000000010b36ea8d -[UIApplication sendAction:to:from:forEvent:] + 92
    10  UIKit                               0x000000010b4e1e67 -[UIControl sendAction:to:forEvent:] + 67
    11  UIKit                               0x000000010b4e2143 -[UIControl _sendActionsForEvents:withEvent:] + 327
    12  UIKit                               0x000000010b4e1263 -[UIControl touchesEnded:withEvent:] + 601
    13  UIKit                               0x000000010b3e199f -[UIWindow _sendTouchesForEvent:] + 835
    14  UIKit                               0x000000010b3e26d4 -[UIWindow sendEvent:] + 865
    15  UIKit                               0x000000010b38ddc6 -[UIApplication sendEvent:] + 263
    16  UIKit                               0x000000010b367553 _UIApplicationHandleEventQueue + 6660
    17  CoreFoundation                      0x000000010a814301 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    18  CoreFoundation                      0x000000010a80a22c __CFRunLoopDoSources0 + 556
    19  CoreFoundation                      0x000000010a8096e3 __CFRunLoopRun + 867
    20  CoreFoundation                      0x000000010a8090f8 CFRunLoopRunSpecific + 488
    21  GraphicsServices                    0x000000010f3ccad2 GSEventRunModal + 161
    22  UIKit                               0x000000010b36cf09 UIApplicationMain + 171
    23  App-Title                           0x0000000109b4a6ff main + 111
    24  libdyld.dylib                       0x000000010d79092d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
1QuickQuestion
  • 729
  • 2
  • 9
  • 25
  • can you show some code and how you pushed your view controller using segue? I bet the problem comes from the Segue transition. – Mj.B May 10 '16 at 16:48
  • You are setting data property in viewcontroller to a wrong value which is crashing the app – Ahmad Ishfaq May 10 '16 at 16:59
  • @Mj.B I did not write any code, I created the button in the storyboard, right clicked and drug to ViewController3, and selected modal. – 1QuickQuestion May 10 '16 at 17:29
  • @AhmadIshfaq I did not set the data property programmatically, could you post an example of how I can do this? (Post it as an answer, so if it works I can accept your answer. – 1QuickQuestion May 10 '16 at 17:31
  • Post the code from your `prepareForSegue:` method in `ViewController` – dan May 10 '16 at 18:13

2 Answers2

0

Have you called method named setData somewhere from your code using ViewController3's object?...the error means you are calling a method which doesn't exist in particular class...try searching setData in your project...check if it has been called using ViewController3's object...hope it helps... :)

Sanman
  • 1,158
  • 11
  • 23
  • I did not write any code, I created the button in the storyboard, right clicked and drug to ViewController3, and selected modal. Is there a quick search function I can use to find this? – 1QuickQuestion May 10 '16 at 17:32
  • use command+shift+f and search method 'setData' in whole project...check for the calls being made to this method...i have dealt with this error while developing app...you are probably calling 'setData' using ViewController3's object...or this might be happening http://stackoverflow.com/questions/2455161/unrecognized-selector-sent-to-instance – Sanman May 10 '16 at 17:55
  • "No Results for 'setData' In Project" comes up in my search – 1QuickQuestion May 10 '16 at 18:16
0

If you set an IBAction, then decide to delete it only by removing the code from your view controller or changing the method's name in your view controller by changing the auto generated IBAction code (similar to below):

@IBAction func setData(sender: AnyObject) { print("Button pressed...") }

You will get this crash.

The reason is that when your view controller is created you told it the selector setData(sender: AnyObject) exists. If you delete or change that code from your view controller without deleting the reference in your storyboard, you get a crash due to an undefined selector.

I suspect you at some point created an IBAction with a setData method and deleted or changed its name in the view controller.

To fix this:

1) Right click on the button (or whatever you added the IBAction to) controller in the storyboard.

2) Look for the setData: method in the view that pops up.

IBAction Storyboard Reference

3) Click the x next to the method name. This deletes the IBAction from the storyboard.

user3847320
  • 823
  • 9
  • 18
  • I removed this, and added it back, but I am still seeing a crash. The only thing I did was right click and select modal when dragging it to the target ViewController. Should I choose "Touch Up Inside" instead? – 1QuickQuestion May 10 '16 at 19:40
  • This is unlikely to be your issue then unfortunately. Apologies! Do you, or did you have a setData method or IBAction at anytime? Or a property called data? – user3847320 May 10 '16 at 20:37
  • No worries, I appreciate any help I can get! Yes, I think (know) I was moving way too fast and I believe I added duplicate references to the IBAction. I added the View Controller and started the lay out, then right clicked the button on ViewController 1>drug it to ViewController3>selected modal.Then I did the same for the button Iadded in ViewController3 back to ViewController. Some time after reviewing some code, I went and drug the button into the ViewController.h as an IBAction (as well as adding the UIbutton declaration) & did the same for the button on the ViewController3.h. – 1QuickQuestion May 10 '16 at 21:04
  • Well, moving to fast, I removed all of the .h references and deleted all of the Button sent events just to make sure I hadn't ruined my app.... but whenever I try to add the modal action back it still crashes with the same error. – 1QuickQuestion May 10 '16 at 21:06
  • 1
    If you post the code from your view controllers in your question it might be helpful. Specifically anywhere you declare properties and any prepareForSegue / performSegue methods. Even though you did this only in storyboard, there may be something floating around causing this issue. – user3847320 May 11 '16 at 13:07