使 popover segue 的 View Controller 保持持久性(仅分配一个实例) [英] Making a popover segue´s View Controller stay persistent (only allocate one instance)

查看:19
本文介绍了使 popover segue 的 View Controller 保持持久性(仅分配一个实例)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最初使用标签栏控制器为 iPhone 编写了我的应用程序,因为视图控制器初始化一次并保持持久性 - 当我点击标签栏时,它不会初始化视图控制器的新实例.

I programmed my app initially for iPhone using a tab bar controller were the view controllers are initialized once and stays persistent - it does not initialize a new instance of the view controller when I tap the tab bar.

在 iPad 上,我使用的是不同的 GUI,而是我有一个始终保留在屏幕上的主视图,其余的是从主视图中分离出来的弹出框.

on the iPad I am using a different GUI were instead I have one main view that always stays on the screen, and the rest are popovers segueing from the main view.

我希望弹出框保持持久性(仅初始化一次)什么是存档的最佳方式.如果我一直在使用 *.xib 文件,我可以在主视图中初始化 popover 的视图控制器,然后在 segueing 时发送它们的副本,这样就只有它们的一个实例.但我使用的是故事板.

I want the popovers to stay persistent (only initialize once) what is the best way of archiving this. If I had been using *.xib files I could have initialized the popover´s view controllers in the main view and then sent a copy of them when segueing, and that way only ever have one instance of them. But I am using Storyboards.

推荐答案

我找到了一个解决方案,实际上很简单,只需使用 UIPopoverController 并使用您想要呈现的视图控制器对其进行初始化.这样它就不会在每次请求弹出框时实例化一个新实例.

I found a solution and actually it´s easy, just use a UIPopoverController and initialize it with the view controller you want to present. In this way it will not instantiate a new instance each time a popover is requested.

if (!popoverController)
    popoverController = [[UIPopoverController alloc]initWithContentViewController:bellViewController];


[popoverController presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
popoverController.delegate=self;

这篇关于使 popover segue 的 View Controller 保持持久性(仅分配一个实例)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆