为什么在获取属性“描述”时会发生崩溃?

时间:2016-08-15 06:54:08

标签: ios objective-c properties

请帮帮我。

为什么会发生以及如何解决?

这是我的代码:

NSString* description = view.description;

如果视图类型为UIButtonUILabel或其他类型,则可用。

但是,如果视图是类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...

0 个答案:

没有答案