Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID
Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.

Loading subview within viewcontroller programmatically

varcharvarchar Posts: 117Registered Users
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




@interface MySubView : UIWebView {

}


@end



MySubView.M




#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




@interface MyViewController : UIViewController {

IBOutlet UIView *mySubView1;

}

@end

Post edited by varchar on

Replies

  • PhoneyDeveloperPhoneyDeveloper Posts: 1,431Registered Users
    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
Sign In or Register to comment.