我正在使用SWReveal滑出式菜单系统。 菜单是从一个数组生成的,一切正常。 E.g。
arrayOfCellData = [cellData(cell : 1, text : "Angles", image : #imageLiteral(resourceName: "Angles.png")),
cellData(cell : 2, text : "Area", image : #imageLiteral(resourceName: "Area.png")),
当我点击特定菜单选项时,我想要转到不同的ViewController。这是我一直使用的代码不起作用。 第1行调用segue A和2 segue B ...
的想法func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
if(indexPath.row == 1 ){
let vc: AnyObject! = self.storyboard?.instantiateViewController(withIdentifier: "A")
self.performSegue(withIdentifier: "A", sender: self)
self.show(vc as! A, sender: vc)
NSLog("A")
}
if(indexPath.row == 2 ){
let vc: AnyObject! = self.storyboard?.instantiateViewController(withIdentifier: "B")
self.performSegue(withIdentifier: "B", sender: self)
self.show(vc as! B, sender: vc)
NSLog("B")
}
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let backItem = UIBarButtonItem()
backItem.title = " "
navigationItem.backBarButtonItem = backItem
if segue.identifier == "A", let nextScene = segue.destination as? A {
nextScene.categoryCounter = 1
}
if segue.identifier == "B", let nextScene = segue.destination as? B {
nextScene.categoryCounter = 2
}
}
答案 0 :(得分:1)
使用SWRevealViewController时,最好不要在故事板中使用segues,而是以编程方式收缩显示视图控制器。试试这个,在didSelectRowAtIndexPath
方法中将以下内容添加到您的代码中。
// Here I get the view controllers I am interested in
let frontStoryboard = UIStoryboard(name: "YourStoryboard", bundle: .main)
let frontVC = frontStoryboard.instantiateInitialViewController()
let rearStoryboard = UIStoryboard(name: "YourOtherStoryboard", bundle: .main)
let rearVC = rearStoryboard.instantiateInitialViewController()
// Construct the SWRevealViewController with your view controllers
if let revealVC = SWRevealViewController(rearViewController: rearVC, frontViewController: frontVC) {
revealVC.modalTransitionStyle = .crossDissolve // Set segue transition
present(revealVC, animated: true, completion: nil) // Segue to view controller
}