Popovers cannot be presented from a view which does not have a window

前端 未结 13 1275
逝去的感伤
逝去的感伤 2020-11-30 08:22

What does this error indicate:

\"Popovers cannot be presented from a view which does not have a window.\"
13条回答
  •  悲&欢浪女
    2020-11-30 09:08

    I got this problem.

    I had a UITabBarController as the detail view, and I set the barButtonItem as the leftBarButtonItem on all three navigation controllers in the tab bar.

    vcChart.navigationItem.leftBarButtonItem = barButtonItem;
    vcAnalysis.navigationItem.leftBarButtonItem = barButtonItem;
    vcTechnicals.navigationItem.leftBarButtonItem = barButtonItem;
    

    Turns out only the last one added is valid, and the previous two would throw the exception when tapped on.

    To fix it, I only set the leftBarButtonItem for the visible view controller, and just switched the barButtonItem to the visible view controller every time the user switched tabs.

提交回复
热议问题