1

I can't see the webview when I launch tha app.. In the delegate that's my code

#import <Cocoa/Cocoa.h>
#include "NewsViewController.h"


@interface AppDelegate : NSObject <NSApplicationDelegate>

@property (assign) IBOutlet NSWindow *window;
@property (nonatomic,strong) IBOutlet NSSplitView *splitView;
@property (nonatomic,strong) IBOutlet NewsViewController *newsViewController;

@end



#import "AppDelegate.h"


@implementation AppDelegate

- (void)dealloc
{
    [super dealloc];
}

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    // Insert code here to initialize your application
    // 1. Create the master View Controller
    self.newsViewController = [[NewsViewController alloc] initWithNibName:@"NewsViewController" bundle:nil];

    // 2. Add the view controller to the Window's content view
    [self.splitView addSubview:self.newsViewController.view];

}

@end

That's my viewcontroller

#import <Cocoa/Cocoa.h>
#import <WebKit/WebKit.h> 



@interface NewsViewController : NSViewController{
    IBOutlet WebView *web;
}

@property (assign) IBOutlet WebView *web;

@end


#import "NewsViewController.h"


@interface NewsViewController ()

@end

@implementation NewsViewController
@synthesize web;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Initialization code here.
    }

    return self;
}

-(void)loadView{

    NSString *urlAddress = @"http://www.google.com/";
    NSURL *url = [NSURL URLWithString:urlAddress];
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
    [[web mainFrame] loadRequest:requestObj];

}

@end

if I out one label on my view in the controller everything is fine but if I put a webview I see only a grey window.

Why this? thanks

Usi Usi
  • 2,967
  • 5
  • 38
  • 69
  • loadView and viewDidLoad are not at all the same methods, and cannot be used interchangeably as you seem to be doing. – CodaFi Aug 04 '13 at 09:12
  • Wich is the solution? I can't understand... LoadView is called every time the controller is loaded... I'm sure because a put an nslog to clarify my doubt – Usi Usi Aug 04 '13 at 09:45
  • Did you manage to resolve this in the end? I'm running into the same problem when creating a new project from scratch – jklp Jan 31 '15 at 00:44

1 Answers1

-1

I do believe you need to call [super loadView] in your loadView implementation.

BergQuester
  • 6,167
  • 27
  • 39
  • -1 Calling through to super with NSViewController, and UIViewController, is unnecessary. He's not seeing anything because he's basically gutted the view loading mechanism by not assigning to `view`. – CodaFi Aug 04 '13 at 09:11
  • `-[UIViewcController loadView]`'s [documentation](http://developer.apple.com/library/ios/documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instm/UIViewController/loadView) explicitly says that the method is used for programmatically creating the view and that the `super` call should not be done. – BergQuester Aug 04 '13 at 19:48
  • However, the [documentation](https://developer.apple.com/library/mac/documentation/cocoa/reference/NSViewController_Class/Introduction/Introduction.html#//apple_ref/occ/instm/NSViewController/loadView) for `-[NSViewController loadView]` is far more terse and says no such thing. In fact, apparently [Apple once recommended using load view as a stand in for view did load to those coming from iOS](http://stackoverflow.com/questions/3422839/viewdidload-in-nsviewcontroller). – BergQuester Aug 04 '13 at 19:48
  • I have a colleague who is doing this because awakeFromNib can be called multiple times when NSTableViewCells are involved. There's a [SO question from someone else on the same issue](http://stackoverflow.com/questions/7092366/awakefromnib-method-called-multiple-times). I personally have never used `loadView`, either in it's iOS or Mac incarnations, but the Mac usage is clear as mud for me. What is the bottom line truth on this method? – BergQuester Aug 04 '13 at 19:49