views:

29

answers:

1

I want to create a simple "control" that will have 4 UILabels defined in it. On one hand I'd like to use Interface Builder to layout my design but on the other hand i'd like to expose some properties that will define contents of each label - is it possible?

@interface CompositeView : UIView{
int numberOne; 
int numberTwo; 
}
@property(nonatomic,assign) int numberOne; //set from view controller and reflected by first UILabel text
@property(nonatomic,assign) int numberTwo; //set from view controller and reflected by second UILabel text

Now ideally I want to do things like:

compositeView.numberTwo=9232;

in my view controller. The problem is .. how do I design view's appearance in IB but expose/implement some of the neccessary logic in code? One idea is to load a NIB file in CompositeView with a view defined and add such view as a subview.. but it feels like fighting with the framework.

+2  A: 

Make your property an "IBOutlet" then wire it up to the label in Interface Builder. You'll probably have to make them strings and do the conversion explicitly, but wiring up a value to be displayed in Interface Builder is one of its strong suits. IBOutlets are for properties you want Interface Builder to be able to see, and IBActions are for methods you want to be able to trigger from a UI control from Interface Builder.

I'd recommend going through some examples and tracing the wiring to understand IBOutlet and IBAction.

samkass