use*_*428 10 uinavigationbar uiviewcontroller uitabbar ios swift
我正在使用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
}
Run Code Online (Sandbox Code Playgroud)
任何人都可以建议我需要在代码中进行更改吗?
这是右舷布局(显示了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
}
Run Code Online (Sandbox Code Playgroud)
尝试这个:
从应用程序委托获取委托:
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
Run Code Online (Sandbox Code Playgroud)
从情节提要中获取您想要呈现的控制器:
Controller *cont=//get the reference from storyboard either using storyboard ID
Run Code Online (Sandbox Code Playgroud)
然后让你的根视图呈现另一个控制器:
[appDelegate.window.rootViewController presentViewController:cont animated:YES completion:^{
DLog(@"presented your view ON TOP of the tab bar controller");
}];
Run Code Online (Sandbox Code Playgroud)
迅速:
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")
})
Run Code Online (Sandbox Code Playgroud)
如果您愿意,您可以将演示内容移动到主线程上!!!!
| 归档时间: |
|
| 查看次数: |
1833 次 |
| 最近记录: |