0

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
Chris Muench
  • 17,444
  • 70
  • 209
  • 362
  • Check the value in `viewWillAppear`. Is it set then? – Axeva Feb 25 '14 at 18:43
  • is your device running an older version of iOS than Simulator ? – Rukshan Feb 25 '14 at 18:44
  • Nothing in viewWillAppear – Chris Muench Feb 25 '14 at 18:45
  • Double-check the segue identifier too. The simulator tends to be a bit tolerant of changes in case, where the actual device is very strict. Make sure it's specified in your storyboard as `continueToStore` and not something like `ContinueToStore` – Axeva Feb 25 '14 at 18:53
  • I would also recommend using `NSLog` to dump out the segue identifier in an else statement if it doesn't match `continueToStore`. – Axeva Feb 25 '14 at 19:00
  • The segue matches and is being run, but somehow the url isn't making it to the StoreWebViewController. I have posted updated code. – Chris Muench Feb 25 '14 at 19:07
  • The problem as I had a weak reference for the store url variable, I changed it to strong and it worked. Where can I find more information on this? – Chris Muench Feb 25 '14 at 19:17
  • This SO answer is pretty good. [Differences between strong and weak in objective-c](http://stackoverflow.com/questions/11013587/differences-between-strong-and-weak-in-objective-c) – Axeva Feb 25 '14 at 21:10

1 Answers1

0

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

Chris Muench
  • 17,444
  • 70
  • 209
  • 362