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

前端 未结 13 1283
逝去的感伤
逝去的感伤 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:03

    There are many ways to get to this error. Basically you need to wait to call the presentPopover command until your calling view is added to a window. I did it this way.

    - (void)viewDidAppear:(BOOL)animated
    {
        [self methodThatDisplaysPopOver];
    }
    

    My presentPopoverFromRect call is inside my methodThatDisplaysPopOver function.

    You could protect every presentPopover call like MobiMaciek suggests with this.

    if (self.view.window != nil)
        [popoverController presentPopoverFromRect:CGRectMake(10, 10, 100, 100) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
    

    However, I think it would be better to understand when self.view.window gets assigned and make sure that you present you popover after the view has a window.

提交回复
热议问题