导航菜单 swift 2.2
Navigation Menu swift 2.2
我使用 SWRevealViewController 创建了菜单,它连接到整个应用程序,但是当我从任何视图的菜单中选择任何行时,它首先转到主页。
任何人都知道为什么以及如何解决这个问题。
问题的原因是我使用 dispatch_async(dispatch_get_main_queue(),{
)}
菜单代码
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)
}
我通过将菜单设置为静态(为所有菜单行创建 8 个单元格)解决了这个问题,然后从每个单元格开始。
我使用 SWRevealViewController 创建了菜单,它连接到整个应用程序,但是当我从任何视图的菜单中选择任何行时,它首先转到主页。 任何人都知道为什么以及如何解决这个问题。
问题的原因是我使用 dispatch_async(dispatch_get_main_queue(),{ )}
菜单代码
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)
}
我通过将菜单设置为静态(为所有菜单行创建 8 个单元格)解决了这个问题,然后从每个单元格开始。