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
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
精彩评论