Question

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    NSString *storyName;
    if (isIPAD)
        storyName = @"Main_iPad";
    else
        storyName = @"Main";

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyName bundle:nil];
    RMViewController *controller = (RMViewController *)[storyboard instantiateInitialViewController];

    NSURL *url = (NSURL *)[launchOptions valueForKey:UIApplicationLaunchOptionsURLKey];
    if (url != nil && [url isFileURL]) {
        [controller handleOpenURL:url];
    }

    return YES;
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
    NSString *storyName;
    if (isIPAD)
        storyName = @"Main_iPad";
    else
        storyName = @"Main";

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyName bundle:nil];
    RMViewController *controller = (RMViewController *)[storyboard instantiateInitialViewController];
    if (url != nil && [url isFileURL]) {
        [controller handleOpenURL:url];
    }
    return YES;
}

This is what I have in my AppDelegate. This helps me overwrite old iPhone data with new as described here: http://www.raywenderlich.com/1980/email-tutorial-for-ios-how-to-import-and-export-app-data-via-email-in-your-ios-app#comments

Now when I call function handleOpenURL data is saved good but when I try to set my IBOutlets based on new data all my outlets are actually nil (tested with breakpoints).

I'm confused because new data I get is actually correct but when I try to assign it to IBOutlet (textfield or label) it doesnt respond.

I think it has got to do with going to background because if I kill the app and start it a bit later app is loaded with new data.

Any help??

Was it helpful?

Solution

This:

RMViewController *controller = (RMViewController *)[storyboard instantiateInitialViewController];

creates an entirely new view controller which is not associated with the app UI at all. Data based operations it performs will likely function quite well but it has no way to change the app UI.

Probably what you should be doing is finding the existing RMViewController instance in the existing UI setup, possibly via the app window and its link to the root view controller.

Failing that, though that probably is the correct solution, at least present the RMViewController instance so that its view is loaded. Again, the presentation would be from the root view controller.


From your comment:

RMViewController *controller = (RMViewController *)self.window.rootViewController;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top