2015-08-25 31 views
1

我正在使用名爲SwiftPages的庫。它工作正常。但是當我從這個視圖控制器執行推Segue到另一個導航欄self.navigationController是零?navigationController在執行segue時爲零?

如何將導航欄添加到推送的VC?

的ViewController

class CoursePageController: UIViewController, UITableViewDataSource, UITableViewDelegate { 

    @IBOutlet weak var ChapterTable: UITableView! 

    @IBOutlet weak var courseDesc: UITextView! 

     var CourseName : String! 

     var ChapName : [String] = [] 
     var ChapId : [String] = [] 


    override func viewDidLoad() { 
     super.viewDidLoad() 



     self.title = CourseName 
     self.courseDesc.text = CourseDescriptionC 
     self.courseDesc.setContentOffset(CGPointZero, animated: true) 
     HUD() 
     ChapterTable.estimatedRowHeight = 120 
     ChapterTable.rowHeight = UITableViewAutomaticDimension 
     getData() 
    } 

    func HUD(){ 
      progress.show(style: MyStyle()) 
    } 

    func getData(){ 
     Alamofire.request(.GET, "http://www.wve.com/index.php/capp/get_chapter_by_course_id/\(CourseIdinController)") 
      .responseJSON { (_, _, data, _) in 
       let json = JSON(data!) 
       let catCount = json.count 
       for index in 0...catCount-1 { 
        let cname = json[index]["CHAPTER_NAME"].string 
        let cid = json[index]["CHAPTER_ID"].string 
        self.ChapName.append(cname!) 
        self.ChapId.append(cid!) 
       } 
       self.ChapterTable.reloadData() 
       self.progress.dismiss() 
     } 
    } 


    func numberOfSectionsInTableView(tableView: UITableView) -> Int { 
     // #warning Potentially incomplete method implementation. 
     // Return the number of sections. 
     return 1 
    } 

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
     // #warning Incomplete method implementation. 
     // Return the number of rows in the section. 
     return ChapName.count 
    } 


    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
     let cell : UITableViewCell = self.ChapterTable.dequeueReusableCellWithIdentifier("ChapCell") as! UITableViewCell 
     cell.textLabel?.text = self.ChapName[indexPath.row] 

     return cell 
    } 


     func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { 
     //Here the navigationController is nil 
self.navigationController?.pushViewController(self.storyboard!.instantiateViewControllerWithIdentifier("LessonController") as! UIViewController, animated: true) 
    //  performSegueWithIdentifier("ChapSegue", sender: nil) 
     } 

編輯

我已經添加了導航控制器作爲我的初始VC。課程頁面控制器顯示在SwiftPages中。

我找不到它是如何呈現的。請看看這個文件。 https://github.com/GabrielAlva/SwiftPages/blob/master/SwiftPages/SwiftPages.swift

在此先感謝!

+0

請檢查您的idenfitier 「LessonController」 –

回答

2

你把NavigationPageController放在NavigationController中嗎?如果是,那麼檢查它是如何呈現的?

如果以模態方式呈現,那麼您將無法獲得navigationController引用。

,如果你有navController爲RootViewController的

if let navController = UIApplication.sharedApplication().keyWindow?.rootViewController as? UINavigationController { 
      //get the nav controller here and try to push your anotherViewController 
     } 
+0

見編輯... – user5184878

+0

你有navigationController爲RootViewController的這是否行得通呢? –

+0

是的。我用這樣的上面。 如果讓navController = UIApplication.sharedApplication().keyWindow?.rootViewController as? UINavigationController的{// 這裏得到導航控制器,並嘗試把你的anotherViewController self.navigationController .pushViewController(self.storyboard .instantiateViewControllerWithIdentifier( 「LessonController」)作爲UIViewController中,動畫:!真的)! } 但它不沒有工作 – user5184878