当我启动应用程序时,我看不到 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
那是我的视图控制器
#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,我只会看到一个灰色窗口。
为什么这个?谢谢