Michael
Michael

Reputation: 743

Why I cannot use IBOutlet named "title" in cocoa?

I have view controller, and inside I have IBOutlet UITextField *title , which is connected with some UITextField in .xib file. When I try to push this view controller to navigation controller, my app throws NSException. And when I change the name of IBOutlet, everything is ok. I saw some guys here had similar issue, but I'm asking WHY is it so ? Is it some kind of reserved word or some bug?

Upvotes: 0

Views: 128

Answers (3)

Joe
Joe

Reputation: 57169

The UIViewController already has a title property that is of type NSString. This is the title you normally see in a navigation conroller. Use a better name like titleLabel otherwise there will be a race to set title, depending on when set it will be an NSString and others some UI element. Your scenario it sounds like the title was set to a UI element and when your navigation controller goes to display it, it is sending a message for NSString which will result in an exception.

Upvotes: 4

Paul Tiarks
Paul Tiarks

Reputation: 1921

UIViewController already has a property named title. You cannot create another property using the same name. Choose a better name.

Upvotes: 0

DHamrick
DHamrick

Reputation: 8488

UIViewController already has a property called title that is conflicting with the IBOutlet.

Upvotes: 0

Related Questions