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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.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-13-2008, 07:42 PM   #1 (permalink)
Registered Member
 
Join Date: Aug 2008
Posts: 95
Default Loading subview within viewcontroller programmatically

Is anyone familiar with how to initialize/load a sub-view programmatically within an existing view which is part of a viewcontroller.

Here is the entire situation:

MyView.nib - created using interface builder. This nib has a UIView and another UIView [subview] within it. It uses MyViewController.

If I assign the class mysubview via interface builder. It works smoothly, no problemo.

But what I am interested in doing is loading the subview programmatically within a view controller, after some logic is done in the main view. (i.e. after I call a web service and depending on the results then I may want to load the subview). If assigning it directly in interface builder, it loads automatically, which defeats purpose of what i want to do.

I was figuring maybe I can load it via assigning the class similar to below within the viewcontroller:

myview1 = mysubview;

Obviously it is not working...





MySubView.h

Code:

@interface MySubView : UIWebView {	
	
}


@end
MySubView.M

Code:

#import "MySubView.h"

@interface MySubView (Private)
- (void) loadMap;
@end

@implementation MySubView


//------------------------------------------------------------------------------
- (void) didMoveToSuperview {
    // this hook method is used to initialize the view; we don't want 
    // any user input to be delivered to the UIWebView.

    self.userInteractionEnabled = NO;
    self.scalesPageToFit = NO;
    self.autoresizingMask = 
    	UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
    
	[self loadMap];
}


MyViewController.h

Code:

@interface MyViewController : UIViewController {

	IBOutlet UIView *mySubView1;
	
}

@end
varchar is offline   Reply With Quote
Old 09-13-2008, 10:09 PM   #2 (permalink)
New Member
 
Join Date: Sep 2008
Posts: 1,431
Default

So what you want is to have a view appear at some time later than when the view controller is pushed?

You can have the view in the nib but just not be already added to the WebView. So it will be created when the viewcontroller is created, your viewcontroller will identify it by an outlet, and at the appropriate time the view controller or the view will addSubview and make it visible.

Alternatively you can place it in its own nib. File's owner will be set to the same viewcontroller as you're using with the WebView so no viewcontroller in the nib. It will also be connected to the viewcontroller by an outlet. You don't use the viewcontroller's initWithNibName to load it. You use the APIs in UINibloading.h
PhoneyDeveloper is offline   Reply With Quote
Reply

Bookmarks

Tags
subview, viewcontroller

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: 260
18 members and 242 guests
14DEV, @sandris, ADY, ArtieFufkin10, ckgni, Dani77, HemiMG, IphoneSdk, jakerocheleau, JasonR, MACralik, NSeven, prchn4christ, Rudy, silverwiz, spiderguy84
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,230
Posts: 380,767
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

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