Controlling a webView from another UIView

Discussion in 'iPhone/iPad Programming' started by FreddieMac2, Jul 23, 2010.

  1. macrumors newbie

    #1
    Hello,

    I currently have a webView (UIWebView) working on FirstViewController. I am opening another window called SecondView controller and based on the user's selection, I want the webView controller on (FirstViewController) to navigate to that webpage. I know that I must access the instance of FirstViewController when I am trying to do this, but I am not sure how to do that without reinitalizing the controller. Here is my sample code:

    NSString *theForm = [myLink objectAtIndex:myRow];

    FirstViewController *myFirstViewController = [FirstViewController alloc];

    [myFirstViewController.webView loadHTMLString:theForm baseURL:nil];

    This does nothing and generates no errors. Any ideas would be helpful.


    FM
     
  2. macrumors member

    ritsard

    #2
    you are missing something in the declaration of your myFirstViewController
     
  3. Moderator

    dejo

    Staff Member

    #3
    I'd suggest creating a property for FirstViewController in SecondViewController and then setting it to the current instance when instantiating your SecondViewController.
     
  4. macrumors newbie

    #4
    Simply dropped a UIWebView var in the second controller and assigned the current webview in the first controller when I launch it. Then I am able to manipulate the UIWebView from the first controller via the second controller.
     
  5. macrumors 68030

    PhoneyDeveloper

    #5
    You must always init an object when you alloc it

    Code:
    FirstViewController *myFirstViewController = [[FirstViewController alloc] init];
    
    Also, the webview doesn't exist yet in the code you show. You must first push the view controller or directly read the view controller's view property.
     

Share This Page