두 개의 nib 파일이있는 두 개의 클래스 (AppDelegate 및 WebViewController)가 있습니다. 하나는 기본 창이고 다른 하나는 WebView가있는 창입니다. AppDelegate에서 실행시 WebViewController Window를 표시하는 코드가 있습니다.WebView가 다른 클래스에서 전달 된 URL을로드하지 않습니다.
- (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]];
내 웹보기는 아무것도하지 않습니다. 로드 된 페이지는 여전히 동일합니다. (있는 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>
누군가가 내 문제를 해결할 수에 대해 어떤 생각을 가지고 다음 (무효) goToURLFromExternal에 대한 콘솔의 출력이 있습니까? 정말 고마워요!
후회할 위험이 있으므로 WebViewController 클래스를 조금 더 문서화 할 수 있습니까? 또한 myWebView가 nil이 아닌지 확인하기 위해 몇 가지 검사를 추가 할 수 있습니다. 그렇다면 loadRequest가 아무 효과가 없을 것입니다. –
답해 주셔서 감사합니다. Maurice Kelly, 새로운 NSObject를 추가하고 Class 속성을 WebViewController로 설정하는 대신 File 's Owner Class 속성을 WebViewController로 설정하여 해결했습니다. 다시 감사합니다! –