-1

I can't figure out how to put multiple sites in an webview. But basically I have one webview, and i want it to load up random sites every-time you go to. I looked at another question like this, but it opened up Safari, i dont want it to open up safaria, i want to stay inside the app in a webview.
This is the questoin i was looking at earlier: Random websites button

It worked good. But i need it to stay in the app in the webview.

Community
  • 1
  • 1

1 Answers1

0

Change :

if ([[UIApplication sharedApplication] canOpenURL:randomURL])
        [[UIApplication sharedApplication] openURL:randomURL];

On:

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL: randomURL];
[self.webView loadRequest:request];
user2545330
  • 408
  • 4
  • 17
  • Thanks for responding. But. . . i am getting an error with the "self.webview" *I did name my webview "webView"*. . . . xcode gives me a solution they put "->" instead of the period. But that doesn't work either. "Property 'webView' not found on object of type 'viewcontroller' *; did you mean to access instance variable 'webView'?". That is what xcode error says. – nmnmnaman Feb 20 '15 at 08:32
  • @nmnmnaman You should change `webView` on your variable name. I have `@property (weak, nonatomic) IBOutlet UIWebView *webView;` So I use `self.webView` – user2545330 Feb 20 '15 at 08:37
  • Ok! Thanks alot, got it working! But how can i get the webview to work on another view controller? The webview works fine on the main view controller, but i can't get it working on another viewcontroller. – nmnmnaman Feb 20 '15 at 08:47
  • i think maybe because the button that is connected IBAction *site is in the first view controller so the code for the random sites are only working for the first view controller and doesn't work for the second view controller. How can i get the where the that button can be used for going to another view controller with the webview and still work? – nmnmnaman Feb 20 '15 at 08:59
  • @nmnmnaman You need to global variable of type nsurl on your second VC. And when button pressed pushVC and set nsurl value. Then when animation finish your second VC will load this url – user2545330 Feb 20 '15 at 09:17
  • Sorry to ask, but im kind of a noob. Can you show me some sample code in what your talking about, please. Sorry. – nmnmnaman Feb 20 '15 at 23:19