2016-08-23 60 views
1

我希望我的swift應用程序在按下UITableViewRowAction「Edit」時打開一個UIViewController(稱爲「SecondViewController」)。不過,我下面的代碼並沒有做任何事情;當我按下「編輯」操作時,絕對沒有任何反應。當按下「編輯」UITableViewRowAction時,無法切換到另一個UIViewController

func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? { 

//Edit action 
let editAction = UITableViewRowAction(style: UITableViewRowActionStyle.Normal, title: "Edit") { (editAction, indexPath) -> Void in 

    let secondViewController = self.storyboard?.instantiateViewControllerWithIdentifier("secondViewController") as! SecondViewController 
    self.navigationController?.pushViewController(secondViewController, animated: true) 

} 

return [editAction] 

} 

這怎麼能解決?這甚至有可能嗎?如果需要更多信息,請發表評論。

+0

我認爲導航控制器是零。請在故事板 –

+0

Ha中添加導航控制器,這非常簡單。不知道我需要有一個uinavigationcontroller這個工作。謝謝。把它作爲答案(只是複製粘貼),以便我可以將其標記爲正確。 – Bossvanlindt

+0

我已經回答。請檢查 –

回答

1

我認爲navigationController是零。您可以通過storyboard添加navigationController或者以編程方式創建它並使ViewController包含tableView作爲rootViewController。這應該工作

+0

Noice的工作噪音。做得好。 – Bossvanlindt

相關問題