ios - 无法从没有窗口的 View 中呈现弹出框 - presentPopoverFromBarButtonItem
<p><p>我试图在 UIBarButtonItem 上显示一个 UIPopover。
我收到此错误:</p>
<pre><code>*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-: Popovers cannot be presented from a view which does not have a window.'
</code></pre>
<p>这是我的代码:</p>
<pre><code>Pop *controller;
UIPopoverController *popoverController;
controller = [ initWithNibName:@"Pop" bundle:nil];
popoverController = [ initWithContentViewController:controller];
;
</code></pre>
<p><strong>解决方案</strong></p>
<p>现在效果很好:</p>
<pre><code>Pop *controller = [ initWithNibName:@"Pop" bundle:nil];
UIPopoverController *popoverController = [ initWithContentViewController:controller];
popoverController.delegate=self;
;
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>弹出框必须呈现在另一个 ViewController 的顶部,您不能让弹出框漂浮在半空中。只需创建一个 ViewController 来呈现 ViewController 。</p>
<pre><code>UIViewController *vc = [ initWithNibName:@"ViewController" bundle:];
self.window.rootViewController = vc;
;
</code></pre>
<p>然后创建并展示您的弹出框。</p></p>
<p style="font-size: 20px;">关于ios - 无法从没有窗口的 View 中呈现弹出框 - presentPopoverFromBarButtonItem,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/18552441/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/18552441/
</a>
</p>
页:
[1]