更新UI的操作必须放在主线程里,否则可能会出错。
This application is modifying the autolayout engine from a background thread after the engine was accessed from the main thread. This can lead to engine corruption and weird crashes.
Stack:(
0 CoreFoundation 0x1c6cce0f <redacted> + 154
1 libobjc.A.dylib 0x1b92f077 objc_exception_throw + 38
2 CoreFoundation 0x1c6ccd3d <redacted> + 0
3 Foundation 0x1d104d81 <redacted> + 280
4 Foundation 0x1cf6fa25 <redacted> + 40
5 UIKit 0x22063c59 <redacted> + 108
6 UIKit 0x220639c3 <redacted> + 514
7 UIKit 0x220639c3 <redacted> + 514
8 UIKit 0x22064115 <redacted> + 84
9 UIKit 0x220633bd <redacted> + 128
10 UIKit 0x22063d75 <redacted> + 162
11 UIKit 0x22064bef <redacted> + 360
12 UIKit 0x21a67751 <redacted> + 164
13 UIKit 0x21775df7 <redacted> + 1364
14 QuartzCore 0x1f589841 <redacted> + 126
15 QuartzCore 0x1f57d78f <redacted> + 354
16 QuartzCore 0x1f57d61f <redacted> + 16
17 QuartzCore 0x1f50e2c3 <redacted> + 370
18 QuartzCore 0x1f52cbb5 <redacted> + 564
19 QuartzCore 0x1f52d653 <redacted> + 162
20 CoreFoundation 0x1c687f15 <redacted> + 20
21 CoreFoundation 0x1c686191 <redacted> + 282
22 CoreFoundation 0x1c5d5553 CFRunLoopRunSpecific + 518
23 CoreFoundation 0x1c5d5341 CFRunLoopRunInMode + 104
24 WebCore 0x207c2c83 <redacted> + 426
25 libsystem_pthread.dylib 0x1bf29a27 <redacted> + 216
26 libsystem_pthread.dylib 0x1bf2994d _pthread_start + 234
27 libsystem_pthread.dylib 0x1bf2749c thread_start + 8
)
解决办法:
dispatch_async(dispatch_get_main_queue()) {
// Do UI stuff here
}
或者
[NSOperationQueue mainQueue] addOperationWithBlock:^{
//Do UI stuff here
}];