简体   繁体   English

从iOS 8 Today Extension中的Storyboard加载特定的ViewController

[英]Load specific ViewController from Storyboard in iOS 8 Today Extension

I am working on an application which provides a new Today Extension/Widget for the Notification Center, as this feature has been added with iOS 8. 我正在开发一个为Notification Center提供新的Today Extension / Widget的应用程序,因为iOS 8已添加了此功能。

However, I need the extension to choose between a couple different view controllers, all set up in Storyboard, based on the values of one simple variable. 但是,我需要扩展以根据一个简单变量的值在几个不同的视图控制器之间进行选择,所有这些控制器都在Storyboard中设置。 So if the user makes changes in the main application, this variable will have a different value and therefore the Today Extension is supposed to load a different initial view controller. 因此,如果用户在主应用程序中进行更改,则此变量将具有不同的值,因此,Today Extension应该加载不同的初始视图控制器。

I have read similar questions and their solutions, so I tried to setup a dummy view controller as the initial view controller on the extension storyboard, create multiple modal segues pointing to the other view controllers, gave all of them an identifier name, disabled animation on the segues and implemented a custom class for the dummy view controller. 我已经阅读过类似的问题及其解决方案,因此我尝试在扩展情节提要板上将虚拟视图控制器设置为初始视图控制器,创建指向其他视图控制器的多个模式选择,并给所有标识符指定标识符,并在其上禁用动画并为虚拟视图控制器实现了自定义类。 This class then calls performSegueWithIdentifier: sender:nil in viewDidAppear: . 然后,此类在viewDidAppear:调用performSegueWithIdentifier: sender:nil However, this seems to be not working with the today extension, in only shows "Unable to load" when I test it in simulator. 但是,这似乎不适用于今天的扩展,当我在模拟器中对其进行测试时仅显示“无法加载”。

Edit: Ok, I was doing something wrong, it actually does work. 编辑:好的,我做错了事,它确实起作用了。 But every time notification center is opened, the content of the displayed view controllers disappears and reappears in a matter of milliseconds, because the dummy view controller is loaded again. 但是,每次打开通知中心时,由于再次加载了虚拟视图控制器,因此显示的视图控制器的内容会在几毫秒内消失并重新出现。 Additionally the extensions height is not changing when presenting one of the other view controllers. 此外,当显示其他视图控制器之一时,扩展高度不会改变。

What could I do to achieve the desired behavior of the today extension? 我该怎么做才能实现今天扩展的预期行为?

Could you use a TableViewController , and put the different logic into TableCell instead of ViewController . 您是否可以使用TableViewController并将不同的逻辑放入TableCell而不是ViewController中 It's easy to select different TableCell against your variable in tableView(tableView:, cellForRowAtIndexPath:) . tableView(tableView:, cellForRowAtIndexPath:)针对变量选择不同的TableCell很容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM