我正在使用3D Touch实现主屏幕快捷方式,并且它运行良好,但是我现在拥有它的方式意味着当快捷方式将用户带到特定的视图控制器时,标签栏和导航栏是丢失。
这是我的代码:
func handleShortCutItem(shortcutItem: UIApplicationShortcutItem) -> Bool {
var handled = false
if let shortcutType = ShortcutType.init(rawValue: shortcutItem.type) {
let rootViewController = window!.rootViewController
switch shortcutType {
case .Favourites:
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let rootController = storyboard.instantiateViewControllerWithIdentifier("favourites") as! FavouritesTableViewController
rootController.parkPassed = DataManager.sharedInstance.getParkByName(NSUserDefaults.standardUserDefaults().stringForKey("currentPark")!)
self.window?.rootViewController = rootController
self.window?.makeKeyAndVisible()
handled = true
}
return handled
}
任何人都可以在代码中提出我需要更改的内容吗?
这是右舷布局(显示了FavouritesTableViewController):
编辑:
这是我更新的代码:
@available(iOS 9.0, *)
func handleShortCutItem(shortcutItem: UIApplicationShortcutItem) -> Bool {
var handled = false
if let shortcutType = ShortcutType.init(rawValue: shortcutItem.type) {
switch shortcutType {
case .Favourites:
print("favourites")
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let rootController = storyboard.instantiateViewControllerWithIdentifier("favourites") as! FavouritesViewController
rootController.parkPassed = DataManager.sharedInstance.getParkByName(NSUserDefaults.standardUserDefaults().stringForKey("currentPark")!)
let root = UIApplication.sharedApplication().delegate as! AppDelegate
if let navCont = root.window?.rootViewController?.navigationController {
navCont.presentViewController(rootController, animated: true, completion: nil)
} else {
root.window?.rootViewController?.presentViewController(rootController, animated: true, completion: nil)
}
root.window?.makeKeyAndVisible()
handled = true
}
}
return handled
}
答案 0 :(得分:2)
试试这个:
从app delegate获取代理:
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
使用想要在故事板中呈现的控制器:
Controller *cont=//get the reference from storyboard either using storyboard ID
然后让你的rootview呈现另一个控制器:
[appDelegate.window.rootViewController presentViewController:cont animated:YES completion:^{
DLog(@"presented your view ON TOP of the tab bar controller");
}];
<强>夫特:强>
var appDelegate: AppDelegate = UIApplication.sharedApplication().delegate()
var cont: Controller = //get the reference form storyboard
appDelegate.window.rootViewController.presentViewController(cont, animated: true, completion: { DLog("presented your view ON TOP of the tab bar controller")
})
如果你愿意,可以在主线程上移动呈现内容!!!!
答案 1 :(得分:2)
所以我得到了解决方案,希望对你有用。
首先,您必须设置Storyboard实例。
let storyboard = UIStoryboard(name: "Main", bundle: nil)
之后,您需要设置要开始导航的位置。
let mynVC = storyboard.instantiateViewControllerWithIdentifier("root") as! UINavigationController
现在你可以设置你想要出现的视图控制器
let playVC = storyboard.instantiateViewControllerWithIdentifier("playVC")
所以现在你可以启动工作流程,但请注意你必须在这样的完成中执行此操作
self.window?.rootViewController?.presentViewController(rootVC, animated: true, completion: { () -> Void in
rootVC.pushViewController(playVC, animated: true)
})
因此你的rootViewController将为你呈现“rootVC”,然后是你的playVC。
我希望它会帮助你们:)
答案 2 :(得分:0)
问题是,您将视图控制器(名为/* (c) 2014 Open Source Geospatial Foundation - all rights reserved
* (c) 2001 - 2013 OpenPlans
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
*/
package org.geoserver.ows.util;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* Provides lookup information about java bean properties in a class.
*
* @author Justin Deoliveira, OpenGEO
* @author Andrea Aime, OpenGEO
*
*/
public class ClassProperties {
private static final List<Method> EMPTY = new ArrayList<Method>(0);
private static final Set<String> COMMON_DERIVED_PROPERTIES = new HashSet<>(
Arrays.asList("prefixedName"));
List<Method> methods;
List<Method> getters;
List<Method> setters;
public ClassProperties(Class clazz) {
methods = Arrays.asList(clazz.getMethods());
)设置为rootController
,而不是window?.rootViewController
提供rootController
。只需改变
window?.rootViewController
到
self.window?.rootViewController = rootController
答案 3 :(得分:0)
如果您像这样使用它,您将被rootview替换为此viewcontroller。所以这将是一个新的独奏页面,它的常规没有navigationController或tabbarController。因为视图层次结构中只有这个新页面。 如果您想从rootview中显示此内容,可以尝试
let root=UIApplication.sharedApplication().delegate as! AppDelegate
if let navCont=root.window?.rootViewController?.navigationController
{
navCont.presentViewController(viewControllerToPresent: UIViewController, animated: true, completion: nil)
}
else{
root.window?.rootViewController?.presentViewController(viewControllerToPresent: UIViewController, animated: true, completion: nil)
}