我有这个应用程序,它有个人资料页面。我在 storyboard
、tableview
和配置文件 View 中有 mainview
。
当我进入个人资料 View 时,我希望能够返回主视图,所以我尝试这样的操作
class ProfileViewController: UIViewController, UITextFieldDelegate, UINavigationBarDelegate{
var bar: UINavigationBar!
override func viewDidLoad(){
super.viewDidLoad()
self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
bar = createBar();
}
func createBar() -> UINavigationBar{
let bar = UINavigationBar(frame: CGRectMake(0,0,self.view.frame.size.width,60))
bar.barTintColor = UIColor(red: 26/255, green: 53/255, blue: 72/255, alpha: 1.0)
bar.delegate = self
let navigationItem = UINavigationItem()
navigationItem.title = "Profile"
let leftButton = UIBarButtonItem(title: "Back", style: UIBarButtonItemStyle.Plain, target: self, action: "goBack:")
let rightButton = UIBarButtonItem(title: "Edit", style: UIBarButtonItemStyle.Plain,target: self, action: nil)
leftButton.tintColor = UIColor.whiteColor()
rightButton.tintColor = UIColor.whiteColor()
//bar.tittleTextAttributes = [UITextAttributeTextColor: UIColor.whiteColor()]
navigationItem.leftBarButtonItem = leftButton
navigationItem.rightBarButtonItem = rightButton
bar.items = [navigationItem]
self.view.addSubview(bar)
return bar;
}
func goBack(sender: UIBarButtonItem!){
if let navController = self.navigationController{
navController.popViewControllerAnimated(true)
}
}
}
我正在使用 SWRevealViewController
。
最佳答案
在 UINavigationController 中嵌入您的 Reveal View Controller。
现在,BackTable View Controller 和 ProfileView Controller 不在 Navigation Controller 的层次结构中。此外,您的 segues 应该是 push segues 才能正常工作。不要使用模态转场。
为了更加清晰,请遵循这个简单的教程:http://code.tutsplus.com/tutorials/ios-from-scratch-with-swift-navigation-controllers-and-view-controller-hierarchies--cms-25462
关于ios - 如何让 UIViewController 弹出 Swift SWRevealViewController?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35037438/