Connecting UILabel to IBOutlet Fails

I have a UIViewController. I boot from the xib file and click on the navigation controller stack.

In the header file for the view controller, I have:

IBOutlet UILabel *myTitle; 

I do nothing with "myTitle" in code; I just set up the connections.

When I compile and run the application, and there are no shortcuts defined in the xib file (and therefore nothing tied to IBOutlet), it works. The view controller animates in the view just fine, showing the view that I created in the interface builder.

If I add a shortcut to xib in the interface builder, but don’t plug it in and recompile it, it still works, showing a label with the default text that I entered for it.

But if I connect IBOutlet myTitle to a label in the interface builder, recompile and run the application, it works fine until I try to push the view controller onto the navigator controller stack, after which I get a failure:

 *** -[UILabel copyWithZone:]: unrecognized selector sent to instance 0x4558e20 

If I unplug the socket again, it resumes work, showing the static label as before. It seems that something funky happens when the view is displayed, because the crash happens when I click the view on the navigation stack.

Shouldn't I add an IBOutlet to UILabel or something else? Or is something else going on? Any suggestions on where to look for problems?

+7
iphone
source share
4 answers

Has your accessory been created for your IBOutlet?

 @property (assign) IBOutlet UILabel *myTitle; 

And then, in your .m file

 @synthesize myTitle 
+6
source share

Yes, it can be caused by an incorrect parameter name, for example. try the following:

 IBOutlet UILabel title; 

and it will throw a similar exception:

 Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UILabel copyWithZone:]: unrecognized selector sent to instance 0x143f520' 
+9
source share

I had the same problem. It turns out * the header is reserved, and Xcode doesn't tell you that. As soon as I renamed it to something else, it worked.

+5
source share

In my case, I had a UILabel in a UIToolBar. For me, the removal of the dashboard and the addition of a new one with the new UILabel was fixed. IB error.

+1
source share

All Articles