对于我的应用程序,我为iPad制作了一个自定义菜单,以替换我用于iPhone的UITabBarController。它工作得很好,除了当我单击一个选项卡时它会将我带到该选项卡并记住状态。我希望它转而将我带到选项卡的主导航控制器(UITabBarController的直接子项,其中有四个),忘记我最后的位置,就像在本机选项卡栏上按两次时会发生什么项目。有什么想法吗?
在AppDelegate.swift中我有
if UIDevice.currentDevice().userInterfaceIdiom == UIUserInterfaceIdiom.Pad{
this_is_an_ipad = true
}
在MainTabBarController.swift中我有
class MainTabBarController: UITabBarController {
override func viewWillLayoutSubviews(){
if this_is_an_ipad{
self.tabBar.hidden = true
}
}
然后我的SideMenuViewController.swift是
import UIKit
class SideMenuViewController: UIViewController {
@IBOutlet weak var homeButtonView: UIView!
@IBOutlet weak var searchButtonView: UIView!
@IBOutlet weak var savedButtonView: UIView!
@IBOutlet weak var categoriesButtonView: UIView!
var buttonColor = UIColor(red: 107.0/255.0, green: 14.0/255.0, blue: 74.0/255.0, alpha: 0.8)
override func viewDidLoad() {
super.viewDidLoad()
homeButtonView.backgroundColor = buttonColor
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
@IBAction func homePressed(sender: AnyObject) {
let tabBarController: UITabBarController? = self.parentViewController?.childViewControllers[1] as? UITabBarController
tabBarController?.selectedIndex = 0
unsetBackgroundColors()
homeButtonView.backgroundColor = buttonColor
}
@IBAction func searchPressed(sender: AnyObject) {
let tabBarController: UITabBarController? = self.parentViewController?.childViewControllers[1] as? UITabBarController
tabBarController?.selectedIndex = 1
unsetBackgroundColors()
searchButtonView.backgroundColor = buttonColor
}
@IBAction func savedPressed(sender: AnyObject) {
let tabBarController: UITabBarController? = self.parentViewController?.childViewControllers[1] as? UITabBarController
tabBarController?.selectedIndex = 2
unsetBackgroundColors()
savedButtonView.backgroundColor = buttonColor
}
@IBAction func categoriesPressed(sender: AnyObject) {
let tabBarController: UITabBarController? = self.parentViewController?.childViewControllers[1] as? UITabBarController
tabBarController?.selectedIndex = 3
unsetBackgroundColors()
categoriesButtonView.backgroundColor = buttonColor
}
func unsetBackgroundColors(){
homeButtonView.backgroundColor = UIColor.clearColor()
searchButtonView.backgroundColor = UIColor.clearColor()
savedButtonView.backgroundColor = UIColor.clearColor()
categoriesButtonView.backgroundColor = UIColor.clearColor()
}
}
答案 0 :(得分:0)
想出来:
await Observable.FromEventPattern<WriteConfirmationEventArgs>(
h => this.WriteCompleted += h,
h => this.WriteCompleted -= h)
.Select(x => x.EventArgs.Id)
.FirstAsync(x => Guid.Equals(x, dto.Id))
.Timeout(TimeSpan.FromSeconds(10));
因此SideMenuViewController.swift的相关部分变为:
let nav = tabBarController?.childViewControllers[desiredIndex] as! UINavigationController
nav.popToRootViewControllerAnimated(true)