There is a button on ViewController A, that when pressed should take me to ViewControllerB which has a UIWebView. That web view should load the desktop version of a website.
These are the steps I take:
ViewController A - Touch button
ViewController B - The UIWebView loads the mobile version of the website instead of desktop version.
NavigationController - Touch the back button -> takes us back to ViewController A
ViewController A - Touch the button again
ViewController B - UIWebView loads the desktop version as desired.
The first time (Step 2), the UIWebView does not load the correct URL and second time (Step 5) it loads the correct URL.
VIEW A-
-(IBAction)ButtonPressed:(id)sender{
HomeAppDelegate *myDelegate = (HomeAppDelegate *)[[UIApplication sharedApplication]delegate];
NSString *titleCaption;WebPageViewController *chosenViewController = [[WebPageViewController alloc] initWithNibName:@"WebPageViewController" bundle:nil];
titleCaption = @"Web PAGE";
chosenViewController.url = [NSURL URLWithString:@"http://www.mydesktopwebsite.com"];
[self.navigationController pushViewController:chosenViewController animated:YES];
myDelegate.navBar.topItem.title = titleCaption;
[chosenViewController release];
}
VIEW B - WebPageViewController.h
@property (retain, nonatomic) IBOutlet UIWebView *WebView;
@property (retain, nonatomic) NSURL *url;
WebPageViewController.m
@synthesize url;
- (void)viewDidLoad{
[super viewDidLoad];
[self.WebView loadRequest:[NSURLRequest requestWithURL:self.url]];}
(Edit note from jcesar: You edited my answer, but I think you wanted to edit your question, so I add the code you put in my answer)
I was using following code which obviously wrong.
NSDictionary *dictionary = @{ @"UserAgent" : @"Safari iOS 5.1 - iPhone"};
[[NSUserDefaults standardUserDefaults] registerDefaults:dictionary];