2015-05-16 19 views
-1

我是新的ios開發。如何添加後退按鈕,這將彈出到前視圖,SWRevealViewController中的所有菜單項

我使用SWRevealViewController在我的應用程序中添加背面菜單。 我想向菜單中的每個視圖添加後退按鈕。 當我點擊後退按鈕時,我總想進入初始(MainTabbedView)視圖

UI流量:

- > MainTabbedVIew - >(toggle_menu) - >(選擇項目1) - >第1項 - >(回到按下) - > MainTabbedView

我發現了一個類似的問題,ios SWRevealViewController pop from rear to front,但它仍然沒有答案。

我添加了一個按鈕來查看和寫一些代碼:

@IBAction func backPressed(sender: UIBarButtonItem) { 
    let storyboard = UIStoryboard(name: "Main", bundle: nil) 
    let vc = storyboard.instantiateViewControllerWithIdentifier("mainTabbedScreen") as UIViewController! 
    self.revealViewController().pushFrontViewController(vc, animated: true) 
} 

它的工作原理,但控制器總是重新創建, 例如:在TabBarController所選標籤總是復位。

我想將NavigationController行爲(彈出前一個視圖)添加到SWRevealViewController菜單項。

我的故事板: http://i.imgur.com/kf5TlAR.png?1

回答

0

我找到了解決方案。 在我的申請,我開始用MMDrawerController代替SWRevealViewController 我用的UINavigationController爲中心的視圖控制器,並在菜單中單擊時顯示來電

pushViewController(controller,animated: true)

我的AppDelegate:

class AppDelegate: UIResponder, UIApplicationDelegate { 

var window: UIWindow? 
var backSideController:MMDrawerController? 
var roorNavigationController:UINavigationController? 


func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 
    // Override point for customization after application launch. 
    var rootController = self.window!.rootViewController 
    let storyBoard : UIStoryboard = UIStoryboard(name:"Main",bundle:nil); 
    var centerContent = storyBoard.instantiateViewControllerWithIdentifier("Center") as! UIViewController 
    var left = storyBoard.instantiateViewControllerWithIdentifier("Left") as! Left 
    var right = storyBoard.instantiateViewControllerWithIdentifier("Right") as! Right 
    roorNavigationController = UINavigationController(rootViewController: centerContent) 
    backSideController = MMDrawerController(centerViewController: roorNavigationController, leftDrawerViewController: left,rightDrawerViewController: right) 
    backSideController!.openDrawerGestureModeMask = MMOpenDrawerGestureMode.PanningCenterView 

    backSideController!.closeDrawerGestureModeMask = MMCloseDrawerGestureMode.PanningCenterView 
    window!.rootViewController=backSideController 
    window!.makeKeyAndVisible() 
    return true 
} 
func pushController(controller: UIViewController){ 
    self.roorNavigationController?.pushViewController(controller,animated: true) 
    self.backSideController!.toggleDrawerSide(MMDrawerSide.Left, animated: true, completion: nil) 
} 

而且某處MyMenuController:

@IBAction func pressed(sender: UIButton) { 
    var newController = self.storyboard?.instantiateViewControllerWithIdentifier("About") as! About 
    var appDelegate:AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate 
    appDelegate.pushController(newController) 

} 
相關問題