I have a table view and in the select cell table view I have put the following code to push the controller. The code is below but it's not working here:
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
println("You selected cell #\(indexPath.row)!")
let second: SecondViewController = SecondViewController()
let navigat = UINavigationController()
navigat.pushViewController(second, animated: true)
}
This would never work!
You are creating a new UINavigationController
object and trying to push your SecondViewController
into it. Ultimately nothing is getting added to visible view hierarchy ie on top of your view controller.
Instead of instantiating a new UINavigationController
object, try this:
self.navigationController?.pushViewController(secondViewController, animated: true)
PS: For better naming convention, I replaced second
with secondViewController
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.