Calling ViewController Method from Delegate

Discussion in 'iOS Programming' started by lng, Dec 9, 2010.

  1. lng macrumors newbie

    Joined:
    Jul 19, 2010
    #1
    Hi, I have searched and read so many pages, but even though tried so many different codes, I couldn't get it working. Here is the situation:

    I have a tabcontroller which its first tab has a view and inside the view there is a UIWebView. Normally when a push notification comes for the app and when user clicks to View button, when app is loading, I parse the the push msg and on ViewController, I rediret the UIWebView to proper page.

    But when the push comes inside the app and when user clicks the View button, I needed to call the ViewController function from AppDelegate to redirect UIWebView to proper page. Somehow I got rid of the errors, but now it is doing nothing. Here are the codes:

    MainViewController.m

    Code:
    - (void) gotoProperPage {
        NSString *gameURL = [@"http://game.com?game?id="stringByAppendingString:appDelegate.gameID];
        [WebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:gameURL]]];
    }
    MyAppDelegate.h

    Code:
    @class MainViewController;
    
    @interface MyAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {
    	MainViewController *mvc;
    }
    
    @property (nonatomic, retain) IBOutlet MainViewController *mvc;
    
    MyAppDelegate.m

    Code:
    #import "MainViewController.h"
    
    @implementation MSLiteAppDelegate
    
    @synthesize mvc;
    ...
    - (void) someMethod{
    [mvc gotoProperPage];
    }
    ...
    
     
  2. vocaro macrumors regular

    Joined:
    Mar 5, 2004
  3. lng thread starter macrumors newbie

    Joined:
    Jul 19, 2010
    #3
    Sorry if I didn't make it clear. "someMethod" is the appDelegate method which I try to call my "gotoProperPage" method from viewController.

    To be clear, when push notf. calls the
    Code:
    (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
    event, I show up an alert and check the user's action with
    Code:
    (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex 
    Actually that's my someMethod.
     

Share This Page