0

Hello I am working on a web view based application, I have a WebController within that I have a variable which holds the current URL.

I have recently added code to launch a view, this works fine, this view also holds another web view, this web view works fine if I load a site into it such as this:

[[mywebview mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:
               [@"http://www.google.com/search?hl=en&q=" stringByAppendingString:@"test"]]]];

However I am trying to access the variable which holds the current URL like this:

 [[mywebview mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:
               [@"http://www.google.com/search?hl=en&q=" stringByAppendingString:currentURL]]]];

However when doing this by linking to the WebController the currentURL seems to equal nothing, however this works perfectly fine when doing it from the first responder (except of course the view no longer shows)

My question is how can I get my currentURL variable working when linked from the WebController?

I am relatively new to cocoa so I am sorry if this is easy question!

EDIT: added from comments

In the method initWithWindowController currentURL is set to @"", and in dealloc to nil. The currentURL comes from the other web view see here:

- (void)webView:(WebView *)wv didStartProvisionalLoadForFrame:(WebFrame *)frame {
    if (frame != [self.webView mainFrame]) 
        return; 
    self.currentUrl = [[[[frame provisionalDataSource] request] URL] absoluteString];
    [self retain]; 
}

I am declaring currentURL in the WebController.h

@interface WebController : NSObject <DOMEventListener>
 { 
   IBOutlet NSString *currentURL; 
 } 
@property (nonatomic, copy) IBOutlet NSString *currentURL; 
@end 

I am trying to use the currentURL in the WebController.m in the DisplayInView function.

-(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 
4

1 回答 1

0

我不知道这是您的问题,还是复制和粘贴错误,但您发布的代码是:

[@"google.com/search?hl=en&q="; stringByAppendingString:currentURL]]]];

它的中间有一个杂散的分号。那甚至不应该编译。

于 2012-12-16T20:50:34.650 回答