![](/img/trans.png)
[英]How can i pass data from UIViewController to SWRevealViewController
[英]How can I make UIViewController pop Swift SWRevealViewController?
我有这个程序,有个人资料页面。 我在storyboard
, tableview
和profile视图中具有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
。
将您的Reveal View Controller嵌入到UINavigationController中。
现在,BackTable View Controller和ProfileView Controller不在导航控制器的层次结构中。 另外,您的segue应该是推送segue,以使其正常工作。 不要使用模态搜索。
请按照以下简单教程进行更清晰的了解: http : //code.tutsplus.com/tutorials/ios-from-scratch-with-swift-navigation-controllers-and-view-controller-hierarchies--cms-25462
首先在UINavigation中嵌入RevealViewController
navigationController!.popToViewController(navigationController!.viewControllers[0], animated: false)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.