I can do this in a tabbed application, no problem, but getting it to work in a single-view application (using xib) is driving me crazy.
I’ve created a new class, WebViewController. The header is:
#import <Foundation/Foundation.h>
#import "GHViewController.h"
@interface GHWebViewController : UIViewController <UIWebViewDelegate>
{
IBOutlet UIWebView *webView;
}
@property (nonatomic, retain) UIWebView *webView;
@end
And the implementation is:
#import "GHWebViewController.h"
@implementation GHWebViewController
@synthesize webView = _webView;
-(void)viewDidLoad
{
[super viewDidLoad];
NSString *fullURL=@"http://www.amazon.com/Books-by-Joel-Derfner/lm/RVZNXKV59PL51/ref=cm_lm_byauthor_full";
NSURL *url = [NSURL URLWithString:fullURL];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
}
@end
So far, so good. But going to the web view is only one option of several available to the user (through bar buttons). So I’ve added a UIWebView to my ViewController but hidden it until the user presses the button to go to the web view.
And here’s where I’m stuck. I’ve tried making this a delegate of that, and that a delegate of the other thing, and I can’t tell what’s right and what’s wrong, and the IBOutlet in WebViewController won’t connect to anything in my ViewController and I’m just getting more and more confused. I tried adding another xib for WebViewController but that just led to disaster. I’m out of my depth here.
So my multi-part question is:
- Is using a
UIWebViewas one of several options as I’ve described possible with a single-view application? - If so, what do I need to do to accomplish it–thinking of a) delegation, b) code, and c) connections in the User Interface?
- If not, how should I approach the task instead?
Off to see Total Recall. Perhaps that’ll clear my head….
I’m not quite sure if I fully understand your question; the paragraph before your 3 questions are somewhat confusing…
But some thoughts:
You don’t need that ivar in interface. Esp. you shouldn’t have
IBOutletin your ivar declaration. If you needIBOutlet, it should be in your@propertydeclaration rather than your ivar.Maybe you don’t really need an
IBOutlet. i.e. you don’t need to put your webView on xib. (you can if you want to, but you don’t need to.)So you can just have an
IBActionhooked up with a button. When that button is clicked, you canalloc inityour webView (and set its frame), add it to yourself.view, and setwebview.delegate = selfor something.Then you can handle the
loadURLand stuff like normal. When you click on that button again (or some other button), you just remove your webview from your view.