【发布时间】:2017-11-22 01:41:38
【问题描述】:
我尝试使用类似的答案来解决我遇到的问题。我是 Xcode 的新手,我有一个控制器,其中包含一个加载我的网站的 uiwebview。我有编码来检测是否按下了某个链接。我遇到的问题是当按下某个链接时,我需要我的第二个控制器充当弹出窗口并显示不同的网页。一切正常,并且该链接被按下我的 NSLog 说它在第二个控制器中,但显示为黑色。这是我在加载我的网页的主视图控制器中的代码:
- (void)viewDidLoad {
[super viewDidLoad];
self.webViewer.delegate=self;
NSString *fullURL = @"https://www.example.com?first_run=true";
NSURL *url = [NSURL URLWithString:fullURL];
//NSLog(@"first page loaded=%@",url);
NSURLRequest *requestObj = [NSURLRequest requestWithURL: url];
[_webViewer loadRequest:requestObj];
}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
self.webViewer.delegate=self;
NSURL *strurl = request.URL;
NSString *urlString = strurl.relativeString;
NSLog(@"link clicked=%@",urlString);
if(//not the right link do this){
}
else{//is the right link do this
NSLog(@"found");
self.popup = [[PopUpController alloc] init];
[self.popup showInView:self.view animated:YES];
return NO;
}
}
@end
那么对于我的第二个控制器,它应该加载不同的网页,但只是得到一个黑屏:
- (void)viewDidLoad {
self.popupView.delegate=self;
NSString *popupURL = @"https://www.example2.com";
NSURL *url_popup = [NSURL URLWithString:popupURL];
NSLog(@"popup page loaded=%@",url_popup);
NSURLRequest *requestObj2 = [NSURLRequest requestWithURL: url_popup];
[_popupView loadRequest:requestObj2];
}
- (void)showAnimate{
self.view.transform = CGAffineTransformMakeScale(1.3, 1.3);
self.view.alpha = 0;
[UIView animateWithDuration:.25 animations:^{
self.view.alpha = 1;
self.view.transform = CGAffineTransformMakeScale(1, 1);
}];
}
- (void)showInView:(UIView *)aView animated:(BOOL)animated{
CGFloat x = self.view.center.x - (aView.frame.size.width);
CGFloat y = self.view.center.y - (aView.frame.size.height);
[aView setFrame:CGRectMake(x,y,aView.bounds.size.width,aView.bounds.size.height)];
[aView addSubview:self.view];
if (animated) {
[self showAnimate];
}
}
任何帮助将不胜感激。我已经尝试了 3 周来搜索和尝试在这个论坛上找到的不同解决方案,但它们都不适用于我的。不确定我只是没有正确实例化我的控制器还是我缺少的一些代码。感谢您的宝贵时间。
【问题讨论】:
标签: ios objective-c xcode uiwebview