你好我正在一個基於Web視圖的應用程序,我有一個WebController,我有一個變量,它包含當前的URL。在ViewController中訪問變量
我最近添加的代碼發動看來,這工作得很好,這種觀點也持其他Web視圖,如果我打開一個網站進去,如這本網站觀點工作正常:
[[mywebview mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:
[@"http://www.google.com/search?hl=en&q=" stringByAppendingString:@"test"]]]];
然而我試圖訪問它保存了當前URL像這樣的變量:這樣做時,通過鏈接到WebController的CURRENTURL似乎等於沒有
[[mywebview mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:
[@"http://www.google.com/search?hl=en&q=" stringByAppendingString:currentURL]]]];
然而,然而,這從第一個響應這樣做時,工作完全正常(當然除了這個觀點不長呃展示)
我的問題是如何讓我的currentURL變量工作時從WebController鏈接?
我是比較新的可可所以我很抱歉,如果這是很容易的問題!
編輯:從評論
在該方法initWithWindowController
currentURL
加入被設置爲@""
,並在dealloc
到nil
。該CURRENTURL來自其他網站的觀點在這裏看到:
- (void)webView:(WebView *)wv didStartProvisionalLoadForFrame:(WebFrame *)frame {
if (frame != [self.webView mainFrame])
return;
self.currentUrl = [[[[frame provisionalDataSource] request] URL] absoluteString];
[self retain];
}
我聲明CURRENTURL在WebController.h
@interface WebController : NSObject <DOMEventListener>
{
IBOutlet NSString *currentURL;
}
@property (nonatomic, copy) IBOutlet NSString *currentURL;
@end
我試圖使用CURRENTURL在WebController.m在DisplayInView功能。
-(IBAction) DisplayInView:(id) sender
{
if ([siteview isInFullScreenMode])
{
[siteview exitFullScreenModeWithOptions:nil];
}
else
{
[[mywebview mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString: [@"google.com/search?hl=en&q="stringByAppendingString:currentURL]]]]; siteview enterFullScreenMode:[[siteview window] screen] withOptions:nil];
}
}
@synthesize siteview;
@end
你可以顯示你設置currentURL var的位置嗎? – geraldWilliam
要回答這個問題,我們需要知道如何聲明'currentURL'以及如何爲其賦值。 –
它在dealloc中設置爲@「」in initWithWindowController :currentURL = nil; 的CURRENTURL來自其他網絡視圖中看到的位置: - (無效)web視圖:(web視圖*)WV didStartProvisionalLoadForFrame:(WebFrame *)幀{ 如果回報;(幀= [self.webView主機]!) self.currentUrl = [[[[frame provisionalDataSource] request] URL] absoluteString]; [self retain]; } – user1887683