我有两个带有两个nib文件的类(AppDelegate和WebViewController):一个是主窗口,另一个是带WebView的窗口。在AppDelegate中,我有这段代码在启动时显示WebViewController窗口:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
self.iTunes = [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"];
[[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveNotification:) name:@"com.apple.iTunes.playerInfo" object:nil];
[self.lyricsTextView setAlignment:NSCenterTextAlignment];
[self refreshLyrics];
// Here I show my WebViewController Window
newWebViewController = [[WebViewController alloc] init];
[NSBundle loadNibNamed:@"WebViewWindow" owner:newWebViewController];
}
我的WebView正确初始化。在WebViewController中我有这个代码:
- (void)goToURLFromExternal:(NSString *)urlToGo {
NSLog(@"%@", urlToGo);
NSURL *newURL = [[NSURL alloc] initWithString:urlToGo];
NSLog(@"%@", newURL);
NSURLRequest *newRequest = [[NSURLRequest alloc] initWithURL:newURL];
NSLog(@"%@", newRequest);
[self.myWebView.mainFrame loadRequest:newRequest];
}
但是当我从AppDelegate使用这段代码时:
[newWebViewController goToURLFromExternal:[[urlArray objectAtIndex:0] stringValue]];
我的WebView没有做任何事情。加载的页面仍然相同。 这里有(void)goToURLFromExternal的控制台输出:(NSString *)urlToGo:
2011-10-04 16:55:54.838 iTunes Lyrics[25379:707] http://lyrics.wikia.com/Cake:Dime
2011-10-04 16:55:54.838 iTunes Lyrics[25379:707] http://lyrics.wikia.com/Cake:Dime
2011-10-04 16:55:54.838 iTunes Lyrics[25379:707] <NSURLRequest http://lyrics.wikia.com/Cake:Dime>
有人有任何想法要解决我的问题吗? 非常感谢你!!!
答案 0 :(得分:1)
您是否已将WebViewController类与WebViewWindow.nib链接?
在WebViewWindow.nib中,将File的Owner Class属性设置为WebViewController。