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 1007627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:38:48+00:00 2026-05-16T08:38:48+00:00

I am relatively new to Objective C/iPhone Development. I am developing a simple app

  • 0

I am relatively new to Objective C/iPhone Development.

I am developing a simple app with two views using a Navigation controller.

The first view contains several buttons a and the second view contains a uiwebview.

The idea is that when a button is pressed it switches to the second view and the web view loads a local html file. Which html file is loaded depends on which button was pressed.

At the moment, the view successfully changes and I can specify a html file to load in the viewdidload method of the webviewcontroller. However this obviosly means that every button triggers the same html file.

Therefore I want to create a NSMutable string which can be accessed from both views(i.e set to a particular filename in the first view and then retrieved when the seoncd view loads).
I have searched the internet for hours and trued to use global variables, the singleton method and accessing a variable in the appdelegate. However no matter which method I try to implement, the uiwebview always displays the same html file(which is the first file alphabetically)

Thanks for any help given. I greatly appreciate any suggestions.

  • 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-16T08:38:49+00:00Added an answer on May 16, 2026 at 8:38 am

    You don’t have to use an NSMutableString for this.

    Add a property url, just a normal NSString, to the second view controller. Before pushing the second view controller onto the navigation stack, you set that url property to the local url you want to load.

    Then, in the second view controller class, implement:

    - (void)setUrl:(NSString *)newUrl {
        if(url != newUrl){
            [url release];
            url = [newUrl retain];
            // [webView load.... load the new url in the webView.
        }
    }
    

    This may be beyond you current knowledge, it contains some vital Objective-C code, like properties, setters and memory management, but just test it out and see what you can do to make it work.

    EDIT You don’t even need this property. Just implement a method like loadUrl: in the webViewController.

    - (void)loadUrl:(NSString *)url {
        // [webView load.... load the URL in the webView
    }
    

    Then, before pushing the webViewController, call this method with the URL you want to load. Avoids a property and gets rid of all the additional memory management code.

    if (self.myWebViewController == nil) {
        //initialise
        webViewController *viewWeb = [[webViewController alloc] initWithNibName:@"webViewController" bundle:[NSBundle mainBundle]];
        self.myWebViewController = viewWeb;
        [viewWeb release];
    }
    [self.myWebViewController loadUrl:@"some-local-url"];
    [self.navigationController pushViewController:self.myWebViewController animated:YES];
    

    As a note, a good practice is to capitalize each classname. Now you have a class webViewController, but in Cocoa it’s common to name the class WebViewController, then you can have a variable called webViewController. Also, you can clearly see whether you are dealing with object (variable) or just a class.

    EDIT Updated
    So I forgot about the fact that the webView will not have been loaded until your view gets loaded. To solve it you’ll have to reintroduce the property I talked about earlier. This time some adjustments are made. In your webViewController class, add the following code:

    - (void)viewDidLoad {
        // viewDidLoad gets automatically called once the view has loaded. Here we want to load the webView.
        [self loadWebView];
    }
    
    - (void)setUrl:(NSString *)newUrl {
        if(url != newUrl){
            [url release];
            url = [newUrl retain];
    
            // Update the webView with the newly set URL. This will not do anything if the view hasn't been loaded, since webView will still be nil. That's why we call loadWebView again when the view gets loaded, in viewDidLoad.
            [self loadWebView];
        }
    }
    
    - (void)loadWebView {
        // Here you'll have to load the url. You can access it using `self.url`.
        //[webView load... 
    }
    

    Now, in the first view controller, update [self.myWebViewController loadUrl:@"some-local-url"]; to self.myWebViewController.url = @"some-local-url";.

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

Sidebar

Related Questions

I'm relatively new to objective-c...I'm using the iphone 3.0 SDK I have a UIView,
I am relatively new to Objective-C / iPhone programming, and have only created single
Relatively new to rails, I'm working on a simple rails app for a few
I am in the process of building my first iPhone app (xCode,objective-c) which has
Im relatively new to iPhone development and Im trying to implement Facebook functions in
I am relatively new to Objective-C and iOS development. What I want to do
I am a relatively new iPhone/objective-c programmer and I have an issue that makes
relatively new to iphone dev, but i was interested in the app Path. its
I am relatively new to Objective C/iOS development so I realize that this may
I am relatively new to Objective-C and I am coming from a Java background,

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.