I have created a custom class that subclasses UIView. I want to do my layout in IB, so have set outlets. The problem is how do I initialise my view so that I get it from the NIB? Any help would be greatly appreciated.
Asked
Active
Viewed 1.3k times
1 Answers
56
Something like this:
UIView *info = [[[NSBundle mainBundle] loadNibNamed:@"InfoWeather" owner:self options:nil] objectAtIndex:0];

kv0
- 914
- 10
- 14
-
Where do I put this? I've put it in my View's class init method and am then adding this view as a subview but still no luck. – John S Sep 27 '11 at 11:58
-
I put it in my UIViewController `init` and call `[self.view addSubview]` too. All looks good. – kv0 Sep 27 '11 at 12:02
-
This is a pretty hard answer to find. Thanks! – Buyin Brian Nov 29 '11 at 03:00
-
Very nice solution. But it only works when the UIView is not to be updated. – Abdurrahman Mubeen Ali Mar 03 '14 at 13:35