Chellange problems


I have a problem that the UIWebView isn’t displayed on the screen.
To solve the chellange I added a new UIViewController with XIB named WebViewController. I added a UIWebView to the XIB and connected this to WebViewController.h.


#import <UIKit/UIKit.h>

@interface WebViewController : UIViewController {
@property (weak, nonatomic) IBOutlet UIWebView *webView;

- (void)loadURL:(NSString *)theLink;


And the loadURL method in WebViewController.m:

- (void)loadURL:(NSString *)theLink {
    NSURL *baseUrl = [NSURL URLWithString:@""];
    NSURL *url = [NSURL URLWithString:theLink relativeToURL:baseUrl];
    NSURLRequest *req = [NSURLRequest requestWithURL:url];
    [_webView loadRequest:req];

And at last the ScheduleViewController method:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    ScheduledClass *c = [classes objectAtIndex:[indexPath row]];
    WebViewController *wvc = [[WebViewController alloc] initWithNibName:nil bundle:nil];
    [wvc loadURL:[c href]];
    [[self navigationController] pushViewController:wvc animated:YES];

The view is pushed, but I don’t see a WebView. What am I doing wrong?


You need to connect the UIWebView object to your webView instance variable. The instance variable is an outlet (a pointer to) the UIWebView on your view (window).

The UIWebView object gets instantiated automatically when the view is pushed.


The variable was created by using the Assistant Editor. But thanks for this:

After I read this I put the

[wvc loadURL:[c href]];

after the

[[self navigationController] pushViewController:wvc animated:YES];

Now the UIWebView works perfect. Thanks


Good deal. (I had made the same mistake.)