Ios 执行segue时navigationController为零?
我正在使用一个名为。它很好用。但是当我执行从这个视图控制器到另一个视图控制器的推送序列时,导航栏self.navigationController是nil吗 如何将导航栏添加到推送的VC中 视图控制器Ios 执行segue时navigationController为零?,ios,swift,uinavigationcontroller,segue,Ios,Swift,Uinavigationcontroller,Segue,我正在使用一个名为。它很好用。但是当我执行从这个视图控制器到另一个视图控制器的推送序列时,导航栏self.navigationController是nil吗 如何将导航栏添加到推送的VC中 视图控制器 class CoursePageController: UIViewController, UITableViewDataSource, UITableViewDelegate { @IBOutlet weak var ChapterTable: UITableView! @I
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中
我不知道它是如何呈现的。请看一下这个文件。
提前谢谢 您是否将CoursePageController放在NavigationController中?如果是,则检查它是如何呈现的 如果以模式显示,则无法获得navigationController引用 如果您将navController作为rootViewController,则此操作将起作用
if let navController = UIApplication.sharedApplication().keyWindow?.rootViewController as? UINavigationController {
//get the nav controller here and try to push your anotherViewController
}
请检查您的标识文件“LessonController”是否将navigationController作为rootViewController?是。我是这样用的。如果让navController=UIApplication.sharedApplication().keyWindow?.rootViewController为?UINavigationController{//在此处获取导航控制器,并尝试推送另一个ViewController self.navigationController!。推送ViewController(self.storyboard!。实例化ViewController标识符(“LessonController”)为!UIViewController,动画:true)}但如果你不在navgitaionController中,它就不起作用了。问题是SwiftPages视图隐藏了我的导航栏。但是我怎样才能把它带回来呢?