即使委托已设置并正在记录,也不会调用动态UIWebView <uiwebviewdelegate>方法</uiwebviewdelegate>

时间:2014-07-11 12:35:39

标签: xcode5 uiwebviewdelegate

我从UIView类动态调用NSObject(创建它并将其添加到堆栈中)来处理数据的收集&#34;从各种来源到我刚刚创建的UIViewController UIViewUiViewController获取数据(返回为HTMLCSS)并将其分配给UIWebview - 这一切都运行正常,看起来很棒。

所有这一切的重点是将网页发送到打印机。但是打印方法并未在上面UIViewController中触发,因为它们位于UIWebViewDelegate方法中。我必须等待它加载:

-(void)webViewDidFinishLoad:(UIWebView *)webView{
DLog(@"WEB VIEW LOADED!!");

if ([[self.webview stringByEvaluatingJavaScriptFromString:@"document.readyState"] isEqualToString:@"complete"]) {

    UIImage *image = [self imageFromWebview:self.webview];

    DLog(@"FINISHED!!");
    for (NSDictionary *printer in self.existingPrinters) {
        //Print here
        }
    }


}
}

这就是我所做的不起作用的事情: (我在.h文件中<UIWebViewDelegate> webview是一个合成强(我也尝试过保留),非原子属性)

我尝试的第一件事是使用viewWillAppear方法将代理人分配到网页视图,然后我尝试了viewDidAppearviewDidLoad;设置代理就像self.webview.delegate = self;和(我也尝试过)[self.webview setDelegate:self];

然后我尝试制作一个.xib文件并以这种方式调用视图;将Web视图附加到files owner并在构建器中设置委托。

WebViewPrintViewController *printerController = (WebViewPrintViewController *)[[WebViewPrintViewController alloc]initWithNibName:@"WebViewPrintViewController" bundle:[NSBundle mainBundle]];

我甚至试图从NSObject类设置委托:

[webPrintVC.webview setDelegate:webPrintVC];

然后我尝试使用StoryBoard调用视图&#34;漫长的道路:&#34;

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
WebViewPrintViewController *myVC = (WebViewPrintViewController *)[storyboard instantiateViewControllerWithIdentifier:@"WebViewPrintController"];

...每次调用视图时,webview委托方法都没有!

我甚至尝试将sleep(2);添加到各种方法中,以查看是否可以使用各种dispatch_async /主线程组合强制View在另一个线程上等待viewController ...

-(void)viewDidAppear:(BOOL)animated{

DLog(@"VIEW DID APPEAR!");
    //self.webview.frame = CGRectMake(self.webview.frame.origin.x, self.webview.frame.origin.y-self.webview.frame.size.height-25, self.webview.frame.size.width, self.webview.frame.size.height);
self.webview.delegate = self;
[self.view setNeedsDisplay]; //another desperate attempt to evoke the delegate methods

}

-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:YES];

self.webview.delegate = self;

[self.webview loadHTMLString:HTML baseURL: nil];
[self.view addSubview:self.webview];

DLog(@"VIEW WILL APPEAR!");

}

同样,当我使用.xib文件时,委托被设置,正如Dlog声明所示:

DLog(@"WEBVIEWCONTROLLER LOADED!!! WHATS THE DELEGATE OF THE WEB VIEW : %@ THIS IS SELF : %@", self.webview.delegate, self);

结果如下:

2014-07-11 08:32:21.708 pos[14292:60b] -[WebViewPrintViewController viewDidLoad] [Line 54] WEBVIEWCONTROLLER LOADED!!! WHATS THE DELEGATE OF THE WEB VIEW : <WebViewPrintViewController: 0xc202c0> THIS IS SELF : <WebViewPrintViewController: 0xc202c0>

我感到茫然......有人可以帮忙吗?

我需要让UIWebViewDelegate方法正常工作。谢谢!

基思

0 个答案:

没有答案