0

I'm attempting to pass the string in the itemSearch text field from my SearchViewController to my CriteriaViewController. I have everything setup according to this thread: Passing Data between View Controllers. The only difference is that rather than passing a BOOL, I'm passing a string. I think my error is how I'm handling this part: controller.itemSearch == self.itemSearch.text;

Error message:

-[CriteriaViewController topViewController]: unrecognized selector sent to instance 0xa99df90
2014-04-17 17:54:20.534 Parse+Storyboard[7095:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:'-[CriteriaViewController topViewController]: unrecognized selector sent to instance 0xa99df90'
*** First throw call stack:
(
    0   CoreFoundation                      0x02a751e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x026338e5 objc_exception_throw + 44
    2   CoreFoundation                      0x02b12243 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
    3   CoreFoundation                      0x02a6550b ___forwarding___ + 1019
    4   CoreFoundation                      0x02a650ee _CF_forwarding_prep_0 + 14
    5   Parse+Storyboard                    0x0000348e -[SearchViewController prepareForSegue:sender:] + 238
    6   UIKit                               0x01857efa -[UIStoryboardSegueTemplate _perform:] + 156
    7   UIKit                               0x0141441c -[UIViewController performSegueWithIdentifier:sender:] + 72
    8   Parse+Storyboard                    0x000032d1 __35-[SearchViewController nextButton:]_block_invoke + 257
    9   Parse+Storyboard                    0x0007a087 __40-[PFTask thenCallBackOnMainThreadAsync:]_block_invoke_2 + 241
    10  libdispatch.dylib                   0x036857b8 _dispatch_call_block_and_release + 15
    11  libdispatch.dylib                   0x0369a4d0 _dispatch_client_callout + 14
    12  libdispatch.dylib                   0x03688726 _dispatch_main_queue_callback_4CF + 340
    13  CoreFoundation                      0x02ada43e __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 14
    14  CoreFoundation                      0x02a1b5cb __CFRunLoopRun + 1963
    15  CoreFoundation                      0x02a1a9d3 CFRunLoopRunSpecific + 467
    16  CoreFoundation                      0x02a1a7eb CFRunLoopRunInMode + 123
    17  GraphicsServices                    0x02cd25ee GSEventRunModal + 192
    18  GraphicsServices                    0x02cd242b GSEventRun + 104
    19  UIKit                               0x012f3f9b UIApplicationMain + 1225
    20  Parse+Storyboard                    0x000028ad main + 141
    21  libdyld.dylib                       0x038cf701 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

SearchViewController.h:

#import <UIKit/UIKit.h>
#import <Parse/Parse.h>
#import <Parse/PFCloud.h>
#import "CriteriaViewController.h"


@interface SearchViewController : UIViewController

@property (weak, nonatomic) IBOutlet UIButton *nextButtonOutlet;

@end

SearchViewController.m:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if([segue.identifier isEqualToString:@"ShowCriteriaSegue"]){
        UINavigationController *navController = (UINavigationController *)segue.destinationViewController;
        CriteriaViewController *controller = (CriteriaViewController *)navController.topViewController;
        controller.itemSearch == self.itemSearch.text;
        }


}

CriteriaViewController.h

#import <UIKit/UIKit.h>
#import <Parse/Parse.h>

@interface CriteriaViewController : UIViewController

@property (nonatomic) IBOutlet UITextField *itemSearch;

@end

enter image description here

Community
  • 1
  • 1
KoftaClarence
  • 125
  • 1
  • 2
  • 11
  • you should double check in the storyboard if you are setting the destination view controller, for the segue identifier "ShowCriteriaSegue", as a UINavigationController. – mownier Apr 18 '14 at 03:47
  • Since I see so many questions like this, I'm curious as to what it is that you don't understand about the error message. What does the message mean to you (I mean just that first line, not the call stack)? – rdelmar Apr 18 '14 at 04:00
  • What confuses me is the part that reads `unrecognized selector sent to instance`. Does this mean that I'm directing it to send the data to CriteriaViewController, when I should be sending it to the navigation controller thats wrapped around it? I've added a screenshot of my storyboard to clear things up. – KoftaClarence Apr 18 '14 at 16:26
  • `[CriteriaViewController topViewController]: unrecognized selector` tells you fairly precisely what's wrong. It means that you have a `CriteriaViewController` and are attempting to execute the method `topViewController` on it, and that class does not implement that method. Usually this error occurs because you somehow picked up the wrong object pointer. – Hot Licks Apr 18 '14 at 16:32
  • And `[SearchViewController prepareForSegue:sender:] + 238` tells you this is happening in `prepareForSegue` at line 238. – Hot Licks Apr 18 '14 at 16:34

2 Answers2

2

This line:

controller.itemSearch == self.itemSearch.text;

== is for comparison not assignment, replace it with just one equal sign.

meda
  • 45,103
  • 14
  • 92
  • 122
1

By reading your crash message:

-[CriteriaViewController topViewController]: unrecognized selector sent to instance 0xa99df90 2014-04-17 17:54:20.534 Parse+Storyboard[7095:60b] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:'-[CriteriaViewController topViewController]: unrecognized selector sent to instance 0xa99df90'

It seems like UINavigationController *navController = (UINavigationController *)segue.destinationViewController; is returning a "CriteriaViewController" instead of a UINavigationController.

Without looking at the storyboard file, it's hard to confirm. You should check your storyboard file; the segue should be pointing to a UINavigationController which contains CriteriaViewController

Z S
  • 7,039
  • 12
  • 53
  • 105
  • Edited my post with a screenshot of the storyboard. As far as I know, the segue does point to a UINavigationController, but I may be wrong. – KoftaClarence Apr 18 '14 at 16:28
  • Your segue is from SearchViewController to CriteriaViewController, not a UINavigationController. Just use this in the prepareForSegue: `CriteriaViewController *controller = (CriteriaViewController *) segue.destinationViewController;` – Z S Apr 18 '14 at 17:23
  • Also, as @meda pointed out, use `controller.itemSearch = self.itemSearch.text;` – Z S Apr 18 '14 at 17:25