I have a UIViewController I am loading from a xib file and pushing onto the navigation controller stack.
In the header file for the View Controller, I have:
IBOutlet UILabel *myTitle;
I don't do anything with "myTitle" in the code yet; I was just setting up the connections.
When I compile and run the application, and there are no labels defined in the xib file (and thus, nothing attached to the IBOutlet), it works. The view controller animates into view just fine, showing the view I built in Interface builder.
If I add a label to the xib in the interface builder, but don't connect it to the outlet, and recompile, it still works, showing the label with the default text I entered for it.
But if I connect the IBOutlet myTitle to the label in interface builder, recompile, and run the app, it works fine until I try to push the view controller onto the navigation controller's stack, at which point I get a crash:
*** -[UILabel copyWithZone:]: unrecognized selector sent to instance 0x4558e20
If I disconnect the outlet again, it resumes working, showing the static label as before. It appears that there's something funky going on when the view gets displayed, because the crash happens when I push the view onto the navigation stack.
Am I not supposed to add an IBOutlet to a UILabel or something? Or is there something else going on? Any suggestions on where to look for trouble?
Yes, it could be caused by wrong param name, e.g. try this:
IBOutlet UILabel title;
and it'll call an exception like that:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UILabel copyWithZone:]: unrecognized selector sent to instance 0x143f520'
Did you create an accessor for your IBOutlet?
@property (assign) IBOutlet UILabel *myTitle;
And then, in your .m file
@synthesize myTitle
I had the same problem. Turns out *title is reserved and Xcode doesn't tell you this. Once I renamed it to something else it worked.
In my case I had a UILabel in a UIToolBar. What fixed it for me was to delete the toolBar and add a new one with a new UILabel. An IB bug.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With