ios - 导航菜单 swift 2.2

标签 ios swift xcode menu swrevealviewcontroller

我使用SWRevealViewController创建了菜单,它连接到整个应用程序,但是当我在任何 View 中从菜单中选择任何行时,它都会首先转到主页。 任何人都知道为什么以及如何解决这个问题。

问题的原因是我使用dispatch_async(dispatch_get_main_queue(),{ )}

enter image description here

菜单代码

extension UIViewController {
func addMenu() {
    navigationController?.navigationBar.barTintColor = UIColor.redColor()
    var image : UIImage = UIImage(named:"menu")!

    if (varView == 0) {

    }
    else if (varView == 1) {
        dispatch_async(dispatch_get_main_queue(),{

             let update = storyboard!.instantiateViewControllerWithIdentifier("updateuser") as! UpdateUserProfileViewController          

              self.navigationController?.pushViewController(update, animated: false)
      )}
    }

  }
  }

最佳答案

无论你做什么与 UI 相关的事情,你都必须在主队列中。您的代码应如下所示

DispatchQueue.main.async { 
       let update = storyboard!.instantiateViewControllerWithIdentifier("updateuser") as! UpdateUserProfileViewController          self.navigationController?.pushViewController(update, animated: false)
}

关于ios - 导航菜单 swift 2.2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44259940/

相关文章:

ios - 支持 64 位,将有效架构设置为 armv8 对吗?

IOS为委托(delegate)函数添加观察者(如)scrollViewDidEndDecelerating :

IOS AdaptiveView Popover 和 NavigationController : how do they work?

ios - iTunes Connect 应用程序预览未被其他大小保存和删除

objective-c - 在 swift 中使用初始化器实现 Objective C 协议(protocol)

ios - Facebook 框架已添加到项目中,但仍然显示 "No such module FBSDKCoreKit"等错误

ios - 在点击屏幕的位置画一条垂直线

ios - myLocationEnabled - 展开时意外发现 nil

ios - Swift xcode 错误 "cannot subscript a value of type ' [ListOfAnimals]'

ios - 如何使用 Swift 以编程方式创建 UILabel?