2015-05-30 43 views
0

我在AppDelegate.swift 手動設置我的初始ViewController後,我的UISwipeGestureRecognizer無法正常工作。UISwipeGestureRecognizer無法手動設置初始ViewController後工作

這是我的AppDelegate什麼樣子:

 self.mainNavigationController = UINavigationController() 
     var mainController: UIViewController? = TineLineViewController() 
     self.mainNavigationController!.pushViewController(mainController!, animated: true) 
     self.window = UIWindow(frame: UIScreen.mainScreen().bounds) 
     self.window!.rootViewController = mainController 
     self.window!.makeKeyAndVisible() 

,這是我UISwipeGestureRecognizer是如何在初始視圖控制器設置:

 let postLeft : Selector = "postLeft:" 
     let postLeftSwipe = UISwipeGestureRecognizer(target: self, action: postLeft) 
     postLeftSwipe.direction = UISwipeGestureRecognizerDirection.Left 
     goToPostButton.addGestureRecognizer(postLeftSwipe) 

這是我postLeft方法,實例化一個新的ViewController並導航到它。

func postLeft(sender: AnyObject) { 

     println("left swipe to push...") 
     let secondViewController = PostCreateController() 
    self.presentViewController(secondViewController, animated: true, completion: nil) 

    } 

當我刷卡時,postLeft方法被調用,我可以看到向左掃推的println,但應用程序不會改變的觀點。

有沒有人有任何解決方案來解決這個問題?

謝謝!

更新:

我改變我的postLeft方法。並通過控制檯,我看到我的新viewController類實例化,但它沒有顯示出來。

回答

0

我想你沒有正確設置你的navigationController,

試試這個,而不是self.navigationController!.pushViewController

let secondViewController = PostCreateController() 
self.presentViewController(secondViewController, animated: true, completion: nil) 
+0

它拋出這個:警告:試圖提出「其視圖不在窗口層次結構中!「和新的視圖沒有顯示:( – solarenqu

+0

檢查,你是不是指出該視圖performSegueWithIdentifer:發件人也 –

+0

我沒有任何performSegueWithIdentifer方法..我沒有故事板neihter .. – solarenqu