请帮帮我。
为什么会发生以及如何解决?
这是我的代码:
NSString* description = view.description;
如果视图类型为UIButton
或UILabel
或其他类型,则可用。
但是,如果视图是类UIWebBrowserView
并且我得到EXC_BAD_ACCESS
,它会崩溃。
为什么会这样?
'description'是类NSObject
的属性,所有类都扩展为NSObject
,而不是我尝试从对象获取此属性时EXC_BAD_ACCESS
,这是类UIWebBrowserView
}?
更多代码:
在UIWebView
中创建ViewController
:
UIWebView* webview = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 120)];
[webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"google.com"]]];
[self.view addSubview:webview];
比使用swizzle机制我得到UIView
点击发生,并尝试从此视图中获取description
。
NSSet * allTouches = [anUIEvent allTouches];
UITouch * touch = [allTouches anyObject];
UIView * view = touch.view;
NSString* description = view.description;
控制台出错:
bool _WebTryThreadLock(bool), 0x17d45fc0: Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be a result of calling to UIKit from a secondary thread. Crashing now...