Creating UIView from NIB and passing it to a view controller
Hi guys, my first post here.
I've been fiddling with some of the basics of iPhone app development, so I hope no body minds this topic again.
Suppose: I have a UIView subclass known as ViewFile.h (&m) and I have a view controller,
FileViewController.h (&m). I have a NIB file called InterfaceFile.xib.
Target: Display view as a subview in a different view which may come from a controller called SourceViewController.h (&m).
1. The way I went about the problem was to create nib file which had its class identity as ViewFile and then instantiating ViewFile in one of the methods in SourceViewController.h.
2. The other was to define a controller (FileViewController) and use the viewDidLoad method to call ViewFile. The InterfaceFile.xib nib file still had ViewFile as the class identity.
But for some reason, I see a grey window whenever I run the application.
Please can anyone guide me in the right direction?
I've been fiddling with some of the basics of iPhone app development, so I hope no body minds this topic again.
Suppose: I have a UIView subclass known as ViewFile.h (&m) and I have a view controller,
FileViewController.h (&m). I have a NIB file called InterfaceFile.xib.
Target: Display view as a subview in a different view which may come from a controller called SourceViewController.h (&m).
1. The way I went about the problem was to create nib file which had its class identity as ViewFile and then instantiating ViewFile in one of the methods in SourceViewController.h.
2. The other was to define a controller (FileViewController) and use the viewDidLoad method to call ViewFile. The InterfaceFile.xib nib file still had ViewFile as the class identity.
But for some reason, I see a grey window whenever I run the application.
Please can anyone guide me in the right direction?
Thank you
Regards
Kartik Thapar
I'm not sure I follow you 100% but I think you are trying to show a view from one viewControiller as a subview of another viewController. The easiest way to do this is create a seperate view class (extend UIView) and then replace the View in IB or in code with the ExtendedView class and instantiate it.
I'm not sure I follow you 100% but I think you are trying to show a view from one viewControiller as a subview of another viewController. The easiest way to do this is create a seperate view class (extend UIView) and then replace the View in IB or in code with the ExtendedView class and instantiate it.
The thing is that I tried with a couple of ways as I mentioned and I'm sorry if you didn't follow it.
I'll break it down to what I want:
I want the view created in InterfaceFile.xib and connected to ViewFile.h which is a subclass of UIView to be displayed as a subview in a different view.
Yeah, that's what I thought. Well make a new subclass of UIView and make both .xib files use this class instead of view and they will both have an instance of that view. Should be straight forward.
Another way, that I don't recommend, would be to instantiate controller1 and pass it's view to controller2. It should work, but it's really ugly in my opinion. You should control each view from it's own viewController.
Yeah, that's what I thought. Well make a new subclass of UIView and make both .xib files use this class instead of view and they will both have an instance of that view. Should be straight forward.
Another way, that I don't recommend, would be to instantiate controller1 and pass it's view to controller2. It should work, but it's really ugly in my opinion. You should control each view from it's own viewController.
But with reference to the first method, can you elaborate a bit more?
Suppose I have a view controller AController who's view is being displayed.
I wish to add a subview to that view which is of type B and B is a subclass of UIView which has its own interface in BGui.xib.