Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7545705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:59:55+00:00 2026-05-30T08:59:55+00:00

I have a requirement to load a UIWebView wrapped inside a UINavigationController, and show

  • 0

I have a requirement to load a UIWebView wrapped inside a UINavigationController, and show it on a modal view. UINavigationController should show the navigation bar at the top with a ‘back’ (I did not find back button, so I used ‘done’ button). I am not supposed to use a nib, so I have to do it programmatically only. The code has to basically serve as a library which can be integrated with any application. It has to work for IPhone and IPad, both.

This is what I have done so far:

I created a WebViewController class –

@interface WebViewController : UIViewController
{
    UIWebView *m_cWebView;
}

@property (nonatomic, retain) UIWebView *m_cWebView;

@end

- (void)loadView
{
    CGRect webFrame = [[UIScreen mainScreen] applicationFrame];
    webFrame.size.height -= self.navigationController.navigationBar.frame.size.height;
    UIWebView *pWebView = [[UIWebView alloc] initWithFrame:webFrame];
    pWebView.autoresizesSubviews = YES;
    pWebView.autoresizingMask=(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth);
    self.view = pWebView;
    pWebView.scalesPageToFit = YES;
    self.m_cWebView = pWebView;
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(back:)];  
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    if( m_cWebView != nil )
    {
        NSURL *url = [NSURL URLWithString:@"http://www.google.co.in"];
        NSURLRequest* request = [NSURLRequest requestWithURL:url];
        [m_cWebView loadRequest:request];
    }
}


- (IBAction)back:(id)sender
{
    [self dismissModalViewControllerAnimated:YES];
}


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    return nil;
}

- (id)init
{
    return self;
}

In the main view controller

@property (retain, atomic) UINavigationController *navCon;

-(IBAction)buttonPressed:(id)sender
{
    if( navCon == nil )
    {
        WebViewController* webViewController = [[WebViewController alloc] init];
        navCon = [[UINavigationController alloc] initWithRootViewController:webViewController];

    }

    [self presentModalViewController:navCon animated:YES];

}

So far, it is working fine. Now my issues:

  1. I am totally new to iOS world. Is the above code correct or are there issues?
  2. Code is supposed to be compiled with Xcode 4.2 with ARC, so I presume that I don’t need to worry about memory.
  3. Is the logic to calculate the initial size of WebView correct (I am taking the size of main screen and deducting the height of navigation bar)?
  4. How do I handle orientation change such that on changing the orientation, my Navigation View and WebView both adjust to the new orientation?

Thanks

Edit:

I tried implementing with the rotation, but I have not been able to get it to work. willRotateToInterfaceOrientation is not getting called on my WebViewController, even though I am returning YES from shouldAutorotateToInterfaceOrientation ( and this method is getting called ). When I tried working with an empty nib ( loading WebViewController with this empty nib ), then it works fine.

Adding the 5th requirement:

  1. One more additional requirement is that when this modal dialog dismisses, the view which presented this, should be in correct orientation (i.e. while the modal dialog is up, the orientation events are also passed on to the view which presented this modal view).

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T08:59:56+00:00Added an answer on May 30, 2026 at 8:59 am

    I found the fix to the rotation problem.
    Replace

    - (id)init
    {
        return self;
    }
    

    with

    - (id)init
    {
        if (self = [super init])
            return self;
        return nil;
    }
    

    and completely remove the following method:

    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
    {
        return nil;
    }
    

    Silly mistakes 🙂
    Now it is rotating fine.

    Can someone still comments on the original requirements?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a requirement to show javascript Ok/Cancel option on page load. So, when
I have a requirement to load a complex object called Node ...well its not
We have a requirement that a user can load any standard image into a
I have a requirement where i want to load pdf document in a web
We have a requirement in which we need to load around 4000 records in
I have a feeling this should be a common requirement, but I can't work
I have got a requirement where I need to write a HTML/CSS, which should
I have table view to load data from an API call. I am using:
I have a requirement to load text labels from our CMS. The content is
I have a requirement to calculate the Moving Range of a load of data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.