【发布时间】:2014-12-10 17:00:42
【问题描述】:
我的故事板中有 6 到 7 个视图控制器,在这个视图控制器中,我将 self.navigationController 设为 nil,但在其他任何地方都可以使用。我在其他地方都做过同样的事情,但这个不起作用。我想不通为什么? 导入 UIKit
class wkScreen2ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
@IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
// tableView.estimatedRowHeight = 500
tableView.rowHeight = UITableViewAutomaticDimension
// tableView.scrollEnabled = true
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// Return the number of rows in the section.
return 3
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) ->
UITableViewCell {
if(indexPath.row == 0){
var cell: Cell1TableViewCell = tableView.dequeueReusableCellWithIdentifier("Cell1") as Cell1TableViewCell
return cell
}
if(indexPath.row == 1){
println("2")
var cell: Cell2TableViewCell = tableView.dequeueReusableCellWithIdentifier("Cell2") as Cell2TableViewCell
return cell
}
if(indexPath.row == 2){
println("3")
var cell: Cell3TableViewCell = tableView.dequeueReusableCellWithIdentifier("Cell3") as Cell3TableViewCell
return cell
}
return UITableViewCell()
}
func navigateTowkScreen3(){
println("next2")
let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
var wkScr3 = mainStoryboard.instantiateViewControllerWithIdentifier("wkScreen3") as wkScreen3ViewController
println(wkScr3)
println(self.navigationController)
self.navigationController?.pushViewController(wkScr3, animated: true)
}
}
https://www.dropbox.com/s/0q7whsgiq3nw14e/Screen%20Shot%202014-12-10%20at%203.39.06%20PM.png?dl=0
【问题讨论】:
-
你确定它有导航控制器吗?并非所有视图控制器都这样做。
-
如何确定它是否有导航控制器,我猜这是一个菜鸟问题,但我对这个视图控制器做了同样的事情,就像其他人做的一样
-
好吧,故事板里面有导航控制器吗?如果是这样,进入这个控制器的 segue 类型是什么? (你能显示故事板的截图吗?)
-
这是屏幕截图。 wkScreen2ViewController 的导航控制器为 nil
标签: swift uinavigationcontroller