当我尝试将customInfoViewController设置为nil时,应用程序失败

时间:2018-07-19 14:16:31

标签: objective-c tvos avplayerviewcontroller

默认情况下,AVPlayerViewController的

CustomInfoViewController属性为nil。 https://developer.apple.com/documentation/avkit/avplayerviewcontroller/2868498-custominfoviewcontroller?language=objc

当我将新的ViewController设置为自定义时,一切都很好:

UIViewController* vc = [[UIViewController alloc] init];
    vc.preferredContentSize = CGSizeMake(1000, 100);
    vc.title = @"TEST";
    self.playerViewController.customInfoViewController = vc; // playerViewController is AVPlayerViewController

但是当我尝试将customInfoViewController设置回nil(以隐藏它)时,它总是失败:

self.playerViewController.customInfoViewController = nil;



*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010746ea56 __exceptionPreprocess + 294
    1   libobjc.A.dylib                     0x0000000106537031 objc_exception_throw + 48
    2   CoreFoundation                      0x00000001074ae54c _CFThrowFormattedException + 194
    3   CoreFoundation                      0x000000010737bccd -[__NSPlaceholderArray initWithObjects:count:] + 237
    4   CoreFoundation                      0x0000000107382694 +[NSArray arrayWithObjects:count:] + 52
    5   AVKit                               0x000000010723997c -[AVPlayerViewController(AVPlayerViewControllerControls) setCustomInfoViewController:] + 88

关于如何隐藏customInfoViewController的任何建议?

1 个答案:

答案 0 :(得分:0)

将属性设置为nil不会隐藏它! 取决于您如何展示CustomInfoViewController。 如果使用present函数显示了它,则应调用dismiss并将其设置为完成块中的nil。 如果仅通过将其视图添加到AVPlayerViewController的视图中来呈现它,则需要将其从其父视图中删除(使用removeFromSuperview()),然后将其设置为nil。