我的UIWebView位于我的视图控制器中,作为SubView添加。我试图从选择器的方法访问它,它将UIViewController作为param,所以我正在做一个子视图数组,迭代它并使用isKindOfClass:UIWebView
来查找我的UIWebView并执行我的选择器,但我可以'在子视图数组中找到webView,我不知道我做错了什么。
这就是我的所作所为:
静态UIWebView * static_iVar = nil;
- (void)viewDidLoad {
[super viewDidLoad];
NSURL *url = [NSURL URLWithString:@"http://example.com"];
[self configureStatic_iVarwithUrlLink:url];
}
-(void)configureStatic_iVarwithUrlLink:(NSURL *)url{
//Configure father class webView...
static_iVar = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, width,height)];
//code...
[self.view addSubview:static_iVar];
NSLog(@"%@",[self.view subviews]);
}
这个Nslog打印出来,所以WebView作为子视图位于我的主视图中:
2015-08-18 16:29:50.719 Hnos Lopez[1785:202794] (
"<_UILayoutGuide: 0x14564180; frame = (0 0; 0 0); hidden = YES; layer = <CALayer: 0x14564330>>",
"<_UILayoutGuide: 0x14564670; frame = (0 0; 0 0); hidden = YES; layer = <CALayer: 0x14562520>>",
"<UIWebView: 0x1456e530; frame = (0 0; 320 568); autoresize = W+H; layer = <CALayer: 0x1456e700>>"
按下后退或刷新按钮时会发生这种情况,并调用选择器方法:
-(void)goBack{
NSArray *subviews = [self.view subviews];
NSLog(@"%@",[self.view subviews]);
for (UIView *subview in subviews){
if([subview isKindOfClass:[UIWebView class]] && [subview respondsToSelector:@selector(goBack)])
{
[subview performSelector:@selector(goBack)];
}
}
}
这就是NSLog打印的内容:
2015-08-18 16:31:44.675 Hnos Lopez[1785:202794] (
"<UIView: 0x14562af0; frame = (0 0; 320 568); autoresize = W+H; layer = <CALayer: 0x145623b0>>",
"<ADBannerView: 0x1453cd00; frame = (0 44; 320 50); clipsToBounds = YES; autoresize = W; layer = <CALayer: 0x1457f620>>",
"<UIActivityIndicatorView: 0x14591910; frame = (150 274; 20 20); hidden = YES; autoresize = W+H; layer = <CALayer: 0x14591b30>>",
"<ADBannerView: 0x146af670; frame = (0 568; 320 50); clipsToBounds = YES; layer = <CALayer: 0x146af880>>"
我的子视图中没有UIWebView