3

我用xib设计了一个ViewController“CommentsViewController”,我试图在单击它时将它呈现在网格单元格上的popovercontroller上......下面是我的代码

CommentsViewController *popOverVC=[[CommentsViewController alloc]init];
            popOverVC.delegate=self;
            popOverVC.commentBoxTextView.text=currentExternalGridCell.ratingValueLabel.text;
            popOverVC.contentSizeForViewInPopover=popOverVC.view.frame.size;
            UIPopoverController *popover =[[UIPopoverController alloc]initWithContentViewController:popOverVC];
            popover.delegate=(id)self;
            popoverC=popover;




            [popover presentPopoverFromRect:currentExternalGridCell.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

但同样给出一个错误..

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIPopoverController _commonPresentPopoverFromRect:inView:permittedArrowDirections:animated:]: Popovers cannot be presented from a view which does not have a window.'

当我调用 presentfromRect 方法时,我检查了 self.view 和 currentexchangegrid 单元格的值都不是 nil ......

编辑

所以我找到了一个解决方案并且很容易......

在显示弹出框之前检查是否 self.view.window!=nil 即,

if(self.view.window!=nil)
      [popover presentPopoverFromRect:currentExternalGridCell.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
4

0 回答 0