Loading View Controller's Outlet view Programmatically?

Short answer: Yes, you can set any property at runtime.

Short answer: Yes, you can set any property at runtime. Longer answer: Yes, You can set any property (e.g. @property (nonatomic, strong) UIView *myView) at runtime.An outlet is simply a property that is defined with IBOutlet to allow interface builder to see it as an available outlet. If you are only going to assign the property at runtime you don't need to define the property as IBOutlet.

Not sure how you've architected your app so don't know if you want to conditionally create a view controller or a view.In any case, at runtime, you set the property as you would any other property based on the condition you are checking.

XJones, I am neither creating conditionally the viewcontroller or the views, all I am doing is setting the view based on which controller it tends to be at. So lets say you have an info button in 20 different view controller's, so realistically I don't want to create 20 different view controllers to have some information about whats there, but what I thought would be easier is to create one generic view controller with multiple views based on which controller it resides in, and set itself as an outlet. Hope it makes some sense?

I could do as beryllium mentioned but it will safe some time. – kforkarim Nov 14 '11 at 18:43 not sure I understand what you are trying to do. In iOS you generally create objects as needed.It's reasonable to have a single view controller that displays different info based on context so you could have a bunch of views defined and when you set a property in that view controller have it create and display the appropriate view and remove/release any views no longer needed.

All of this of course, at runtime. – XJones Nov 14 '11 at 18:49 XJones, I guess adding and removing view's is the only way, I was thinking maybe connecting to file's owner outlet initially would do the trick, as those view in interface builder are the objects as well right? So if you know which view you need to connect to the file owner, then no need to keep on removing/releasing and then adding.. just trying to safe some iterative process here.. – kforkarim Nov 14 '11 at 18:57 you can implement it that way.

E.g. You can create 20 views in your NIB file and give them tags. When you want to set the outlet, look up the view with a specific tag, assign it to the outlet and add it to the superview.

When setting the outlet you would also remove the old view from the superview. – XJones Nov 14 '11 at 19:20 just to clarify something, how to set the outlet with respect to tag? Is it something that can be done programmatically?

Adding and removing portion I got it, but just trying to figure out how would I assign it to outlet, as per with tags. Thanks for giving the update on tags as well, that's something I didn't had thought about. – kforkarim Nov 14 '11 at 19:38.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions