child view controller: should have parent view controller: but requested parent is:

iOS 11.0出现的崩溃。

其他版本未出现崩溃。

原因:

之前代码不规范,将childViewController上的View添加当前视图,但是未添加childVC

[self.view addSubview:self.childVC.view];

应添加

[self addChildViewController:self.childVC];
 [self.view addSubview:self.childVC.view];

崩溃信息

Device Version: iPhone 6S
iOS Version: 11.0
App Version: 6.8.6
Build Version: 6.8.6.0.1
ibuild Build Version: 001163
ibuild Build Date Time: 2017-09-08 11:40:34
Crash Date Time: 2017-09-08 17:20:45
================================
Name: UIViewControllerHierarchyInconsistency
Reason: child view controller: should have parent view controller: but requested parent is:
UserInfo: (null)


CallStackSymbols:
0 CoreFoundation 0x0000000185917d50 + 148
1 libobjc.A.dylib 0x0000000184e2c528 objc_exception_throw + 56
2 CoreFoundation 0x0000000185917c80 + 0
3 UIKit 0x000000018ed41320 + 304
4 UIKit 0x000000018f832270 + 544
5 UIKit 0x000000018f82bdf8 + 568
6 UIKit 0x000000018f83320c + 1108
7 UIKit 0x000000018f82b7cc + 56
8 UIKit 0x000000018ed60c60 + 1176
9 UIKit 0x000000018ecd1440 + 2140
10 UIKit 0x000000018ecd0bb4 + 80
11 UIKit 0x000000018ed2ca28 + 856
12 UIKit 0x000000018ed5e45c + 760
13 UIKit 0x000000018ed5d6b4 + 788
14 UIKit 0x000000018ed53c18 + 2520
15 UIKit 0x000000018ed52d08 + 1168
16 UIKit 0x000000018ed52770 + 124
17 UIKit 0x000000018ed52698 + 188
18 UIKit 0x000000018eca8d70 + 1256
19 QuartzCore 0x00000001898dbcc8 + 184
20 QuartzCore 0x00000001898dfda8 + 332
21 QuartzCore 0x000000018984fb50 + 336
22 QuartzCore 0x0000000189875f6c + 540
23 UIKit 0x000000018ec9e5f4 + 256
24 CoreFoundation 0x00000001858bf8b8 + 32
25 CoreFoundation 0x00000001858bd270 + 412
26 CoreFoundation 0x00000001858bd82c + 1292
27 CoreFoundation 0x00000001857de2d8 CFRunLoopRunSpecific + 436
28 GraphicsServices 0x0000000187663f84 GSEventRunModal + 100
29 UIKit 0x000000018ed0f5e0 UIApplicationMain + 208
30 xxxxx 0x000000010095a470 main + 164
31 libdyld.dylib 0x000000018530256c + 4


推荐阅读更多精彩内容