Mac OS X使用WebView对象

时间:2013-08-04 01:13:20

标签: objective-c macos webview

当我启动应用程序时,我无法看到webview .. 在委托中,这是我的代码

#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

这是我的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

如果我在控制器中查看我的视图中的一个标签,一切都很好但是如果我放了一个webview,我只看到一个灰色的窗口。

为什么这样? 感谢

1 个答案:

答案 0 :(得分:-1)

我相信您需要在loadView实现中调用[super loadView]