我有这个应用,它有个人资料页。我在mainview
、storyboard
和纵断面图中有tableview
。
当我转到profile view时,我想能够回到mainview,所以我尝试这样的操作
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中嵌入显示视图控制器。
现在,BackTable视图控制器和ProfileView控制器不在导航控制器的层次结构中。另外,你的segues应该是push segues才能起作用。不要使用模态分段。
请按照此简单教程进行操作,以获得更清晰的信息:http://code.tutsplus.com/tutorials/ios-from-scratch-with-swift-navigation-controllers-and-view-controller-hierarchies--cms-25462