1

I know this question has been asked, but none of the answers I saw helped me. If you think I missed one that may help, please let me know. I saw other examples where the view controller simply did not have the variable that was trying to be set, but that is not my case.

I'm getting this error during a segue:

-[EditPropertyViewController setLawnNumber:]: unrecognized selector sent to instance 0x19a301e0

whenever I hit this if block inside of prepareForSegue:

if( [segue.identifier isEqual:@"editProperty"])
{
    EditPropertyViewController *destView = segue.destinationViewController;
    destView.lawnNumber = _lawnNumber;
    destView.latitude = _latitude;
    destView.longitude = _longitude;
    destView.address = _serviceAddressLabel.text;

}

I do have #import "EditPropertyViewController.h" at the top of my .m file. I do have a segue with identifier "editProperty", and it pushes a view control that is set to type EditPropertyViewController.

Here is EditPropertyViewController.h, showing that I have the variables I'm trying to set:

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

@interface EditPropertyViewController : UIViewController
@property (nonatomic, strong) GMSMapView *mapView;
@property (nonatomic, strong) GMSCameraPosition *camera;
@property(strong, nonatomic) NSString *address;
@property (nonatomic) CLLocationDegrees latitude;
@property (nonatomic) CLLocationDegrees longitude;
@property (nonatomic) int lawnNumber;

@end

I use this same method with the same variable types and what not to pass data during other segues, but I don't see what I'm doing differently here to cause this problem. I haven't created a [customVC setVariable:] method anywhere else, and haven't run in to this issue yet.

Any advice is appreciated!

Edit - following @David H's advice, I added these two lines before trying to set values:

NSLog(@"Actual class is %@", NSStringFromClass([destView class]));

assert( [destView class] == NSStringFromClass([destView class]));

Which caused the following output:

    2015-02-27 16:56:27.623 LawnGuru[2730:460942] Actual class is EditPropertyViewController 
Assertion failed: ([destView class] == NSStringFromClass([destView class]))

Copy/pasted from the storyboard, this is the type of the VC I'm trying to segue to: "EditPropertyViewController" and this is the .h file I'm accessing: #import "EditPropertyViewController.h"

Jake T.
  • 4,308
  • 2
  • 20
  • 48
  • Are you using a @synthesize for the lawnNumber property in your EditPropertyViewController.m? If so, please show it. – picciano Feb 27 '15 at 21:47
  • I'm not. I haven't used @synthesize in my entire project. In fact, the only thing I've changed on EditPropertyViewController.m is adding (IBAction)prepareForUnwindEditProperty:(UIStoryboardSegue *)segue{}, and it's empty, so that I could hit unwind on a future view controller to go back to it. Nothing else has been touched. – Jake T. Feb 27 '15 at 21:48
  • @JakeT.: Open the header file directly and check the property is there or not (I mean not open by jump by definition) – Midhun MP Feb 27 '15 at 21:50
  • If this just started happening, try doing a project->clean then restart Xcode. – picciano Feb 27 '15 at 21:50
  • 1
    Does XCode crash? I have a hard time understanding how you're seeing the lldb error message unless it's your program that's crashing. – stevesliva Feb 27 '15 at 21:53
  • @MidhunMP Opening EditPropertyViewController.h from the project navigator, using "Jump To Definition" from PropertyViewController.m (where the error is occuring), and by going to the view controller on the storyboard that I am segueing to and opening the assistant editor all show the same file, and the property is definitely there. It's "lawnNumber", and the error is saying that [EditPropertyViewController setLawnNumber]" with a capital L is being called. Could that be a source of error? picciano - it happened when I added the offending lines stevesliva - yes, the program is crashing – Jake T. Feb 27 '15 at 21:54
  • possible duplicate of [How can I debug 'unrecognized selector sent to instance' error](http://stackoverflow.com/questions/25853947/how-can-i-debug-unrecognized-selector-sent-to-instance-error) – Hot Licks Feb 27 '15 at 21:56
  • What is the definition of _lawnNumber in your source VC? – Paulw11 Feb 27 '15 at 21:58
  • @Paulw11 from the .h file of the source VC: @property(nonatomic) int lawnNumber; – Jake T. Feb 27 '15 at 22:02
  • @HotLicks while the question is similar, none of the answers are relevant to me. – Jake T. Feb 27 '15 at 22:06
  • That's what they all say. I'm guessing that you use an option that requires you to explicitly use `synthesize`, and you didn't. – Hot Licks Feb 27 '15 at 22:11
  • 1
    You might try deleting the lawnNumber property in editPropertyViewController, and remake it, just to make sure something screwy didn't happen in Xcode. I don't see anything wrong with your code. – rdelmar Feb 27 '15 at 22:11
  • @rdelmar Heh, I have no clue why that worked, because I checked the spelling so many times, and I actually rearranged the properties so address was the first one I changed, and it gave me an error on that line instead of the one where I set lawnNumber... I don't know why just deleting the property for lawnNumber and retyping it worked, but it did! Submit an answer and I'll mark it as correct. – Jake T. Feb 27 '15 at 22:17
  • @HotLicks Nope, rdelmar's idea to just delete the properties and rewrite them worked. Not sure why, because the spelling was exactly the same, but just rewriting lawnNumber fixed the error for every other property. – Jake T. Feb 27 '15 at 22:19

2 Answers2

1

Sometimes, from what I've seen in other questions, Xcode seems to have a hiccup, and the only way to fix the situation is to remove the allegedly offending code and re-add it. Try deleting the lawnNumber property, and re-doing it.

rdelmar
  • 103,982
  • 12
  • 207
  • 218
  • Even though I was getting the error on whichever property I set first, rewriting just lawnNumber fixed the whole thing. Thanks! – Jake T. Feb 27 '15 at 22:54
0

Almost for sure your dest view controller is not what you think it is. Try this:

EditPropertyViewController *destView = segue.destinationViewController;
NSLog(@"Actual class is %@", NSStringFromClass([destView class]));

if ( [destView class] == [EditPropertyViewController class] )
    NSLog(@"Class is good, responds to selector=%d", [destView respondsToSelector:@selector(setLawnNumber:)] );
}
David H
  • 40,852
  • 12
  • 92
  • 138
  • Adding the bottom two lines before I try to set values, I get this output: 2015-02-27 16:56:27.623 LawnGuru[2730:460942] Actual class is EditPropertyViewController Assertion failed: ([destView class] == NSStringFromClass([destView class])). I'll update my question with this information. Copy/pasted from the storyboard, this is the type of the VC I'm trying to segue to: "EditPropertyViewController" and this is the .h file I'm accessing: #import "EditPropertyViewController.h" – Jake T. Feb 27 '15 at 21:59
  • 1
    That assert makes no sense. A class object pointer would never be equal to a sting pointer. – Hot Licks Feb 27 '15 at 22:09
  • 1
    The assert() was incorrect - I changed that bit of code. Retry it now - see if what the responds to selector says. @HotLicks right - trying to type code into these answers is more difficult since SO changed the editor...The test on the respondsToSelector would pick up an Xcode error using an older .o without that property defined. – David H Feb 27 '15 at 22:13
  • @DavidH the if statement passed true. Someone else suggested in a comment to just delete the properties and rewrite them. I had tried rearranging the order I set the properties in the source VC to see if it was that property or something wrong with the dest VC, and any order threw an error at the first property I tried to set. I deleted only the lawnNumber property and rewrote it exactly the same (as far as I can tell), and the whole segue worked. Any idea why rewriting one property fixed all of them? – Jake T. Feb 27 '15 at 22:23
  • Probably the class wasn't properly compiled. Xcode does a lot of caching. That you would get a 'responds to selector' success, but then get a failure on actually calling it is mystifying. Normally when bizarre things happen the best thing to do is removed the derived folder and build from scratch. I rarely find this necessary but of course sometimes it is. The normal reason for the failure here is as I said - the class of the controller is not what you think it is! Swift will help people catch this kind of problem earlier. – David H Feb 27 '15 at 22:29