简体   繁体   中英

Passing data via prepareForSegue works on simulator but NOT on device

I have the following code that passes a URL to the destination controller which loads a url

StoreURLViewController.m

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if([segue.identifier isEqualToString:@"continueToStore"])
    {
        StoreWebViewController *controller = (StoreWebViewController *)segue.destinationViewController;

        NSString *url = self.storeUrl.text;
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        [defaults setObject:url forKey:@"storeUrl"];
        [defaults synchronize];

        controller.storeUrl = [StoreUrlViewController checkAndPrependProtocolForApiUrl:url];
        NSLog(@"%@", controller.storeUrl);
    }
}

I have the following code that checks to see if it has a url and loads a web view

StoreWebViewController.m

- (void)viewDidLoad
{
    [super viewDidLoad];
    NSLog(@"%@",self.storeUrl);
    if (self.storeUrl != nil)
    {
        [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[StoreWebViewController checkAndPrependProtocolForUrl:self.storeUrl]]]];
        self.webView.delegate = self;
    }    
}

On the simulator the URL is a string and loads the web page, but on the device it is nil and doesn't load the page.

Device Output for input http://google.com

2014-02-25 14:05:48.883 PHP Point Of Sale[2784:60b] (null)
2014-02-25 14:05:48.970 PHP Point Of Sale[2784:60b] (null)

Simulator Output for http://google.com

2014-02-25 14:09:10.703 PHP Point Of Sale[31811:70b] http://google.com
2014-02-25 14:09:10.775 PHP Point Of Sale[31811:70b] http://google.com

I had a weak reference to storeUrl. I changed it to strong and now it works in the simulator and device.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM