Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 09-16-2010, 06:30 AM   #1 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 22
dethmaShine is on a distinguished road
Default 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?

Thank you
Regards

Kartik Thapar
dethmaShine is offline   Reply With Quote
Old 09-16-2010, 06:47 AM   #2 (permalink)
Registered Member
 
Join Date: Aug 2010
Location: Edinburgh
Posts: 209
Justinmichael is on a distinguished road
Default

Quote:
Originally Posted by dethmaShine View Post
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?

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.
__________________
Justinmichael is offline   Reply With Quote
Old 09-16-2010, 06:53 AM   #3 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 22
dethmaShine is on a distinguished road
Default

Quote:
Originally Posted by Justinmichael View Post
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.
dethmaShine is offline   Reply With Quote
Old 09-16-2010, 07:04 AM   #4 (permalink)
Registered Member
 
Join Date: Aug 2010
Location: Edinburgh
Posts: 209
Justinmichael is on a distinguished road
Default

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.

Code:
UIViewController* controller1 = [[UIViewController alloc] init ....];
UIViewController* controller2 = [[UIViewController alloc] init....];
[controller2.view addSubview controller1.view];
Hope this helps,
__________________
Justinmichael is offline   Reply With Quote
Old 09-16-2010, 07:19 AM   #5 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 22
dethmaShine is on a distinguished road
Default

Quote:
Originally Posted by Justinmichael View Post
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.

Code:
UIViewController* controller1 = [[UIViewController alloc] init ....];
UIViewController* controller2 = [[UIViewController alloc] init....];
[controller2.view addSubview controller1.view];
Hope this helps,
Thanks!

Even I don't think the second is a good one.

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.

Can you please elaborate on this?

Thanks
dethmaShine is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 321
17 members and 304 guests
2ndSegment, cayladv57, cgokey, dermotos, djohnson, Domele, Hamad, heshiming, linkmx, markuschow, Objective Zero, pungs, Rudy, Sloshmonster, teebee74, v1n2e7t
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,655
Threads: 94,116
Posts: 402,889
Top Poster: BrianSlick (7,990)
Welcome to our newest member, pungs
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 10:56 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0