francesco.venica
francesco.venica

Reputation: 1721

set programmatically UIView

I have a little problem, why does this work:

self.view = mySecondView; (the view was changed)

while this:

self.myView = mySecondView; (the view was not changed)

doesn't? I have created an outlet

IBOutlet UIVIew* myView; 

connected in IB. In my .m I've created a new view (mySecondView) programmatically, than with an action I try to set myView with this new view, the resolute is not work. where is the error?

Upvotes: 1

Views: 252

Answers (2)

jbat100
jbat100

Reputation: 16827

self.view = mySecondView; (the view was changed)

This probably works because self is a UIViewController which has a view property (allowing you to use the dot notation) out of the box. Create a myView property:

@property (retain, nonatomic) UIView *myView;

Upvotes: 0

Caleb
Caleb

Reputation: 124997

If myView isn't declared as a property you can't use dot notation to access it. Try adding this to your .h file:

@property (retain, nonatomic) UIView *myView;

and this to your .m file:

@synthesize myView;

Upvotes: 2

Related Questions