Tristan
Tristan

Reputation: 3885

IPhone: Set a controller variable from Interface Builder

I have a view controller that is used with multiple xib files. At the moment I just have a different outlet for the view in each xib, and I do different things based on which of the outlets is set! But what I would rather do is set a variable from Interface Builder on the view controller such as an enum or int which would identify which of the xibs the controller is linked to!

Is there anyway to do this or can someone suggest an alternative?

I will say that extracting the common code into a class and just having different controllers for each xib is an option but I would rather not do it this way as it would create lot more files/code then is honestly needed as the code i almost identical except for a few small switch statements for each xib

Upvotes: 2

Views: 442

Answers (1)

theChrisKent
theChrisKent

Reputation: 15099

You can set the Tag property of the view directly from the property inspector in Interface Builder. This property can then be accessed in code.

Documentation: http://developer.apple.com/library/ios/documentation/uikit/reference/UIView_Class/UIView/UIView.html#//apple_ref/occ/instp/UIView/tag

Upvotes: 4

Related Questions