简体   繁体   English

navigationController在执行segue时为零?

[英]navigationController is nil while performing segue?

I am using a library called SwiftPages . 我正在使用一个名为SwiftPages的库。 It works fine. 工作正常。 But when i perform a Push Segue from this View Controller to another the navigation bar self.navigationController is nil ? 但是,当我执行从此View Controller到另一个View的Push Segue时,导航栏self.navigationController为nil吗?

How can i add the navigation bar into the pushed VC ? 如何将导航栏添加到推送的VC中?

ViewController 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)
        }

EDIT 编辑

I have added the Navigation controller as my Initial VC. 我已将导航控制器添加为我的初始VC。 The Course page Controller is shown from the SwiftPages. 从SwiftPages中显示课程页面控制器。

I can't find how it is being presented. 我找不到它的呈现方式。 Please take a look at this file. 请看一下这个文件。 https://github.com/GabrielAlva/SwiftPages/blob/master/SwiftPages/SwiftPages.swift https://github.com/GabrielAlva/SwiftPages/blob/master/SwiftPages/SwiftPages.swift

Thanks in Advance! 提前致谢!

Did you put CoursePageController in NavigationController? 您是否将CoursePageController放在NavigationController中? If yes then check how it is presented? 如果是,则检查其显示方式?

If it is presented modally then you won't get the navigationController reference. 如果以模态显示,则不会获得navigationController参考。

This will work if you have navController as rootViewController 如果您将navController作为rootViewController,这将起作用

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM