How to navigate a page into another view controller using tableview did select method


How to navigate a page into another view controller using tableview did select method



This is my code to navigate from one viewController to another viewControler but i can't navigate. data is rest api nsobject data that stored category from rest api as name, entertainment is a category . when i tap on category goto another viewController


func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
{
print("hello welcome on this news page")

// dismiss(animated: true, completion: nil)

if data[indexPath.row].name == "Entertainment"
{
let storyboard = UIStoryboard(name: "Main", bundle: Bundle.main)
let destination = storyboard.instantiateViewController(withIdentifier: "WhiteViewController") as! FourthViewController
navigationController?.pushViewController(destination, animated: true)
dismiss(animated: true, completion: nil)
print("Welcome on Business..!")
}
}





remove this line of code dismiss(animated: true, completion: nil)
– Rahul Dubey
Jun 28 at 12:02





i need to close slide menu on did select method when click on row @IBAction func CloseSlideMenu(_ sender: UIButton) { dismiss(animated: true, completion: nil) }
– sapna
Jun 28 at 13:09






is there any navigationController embedded in your storyboard ?
– Abu Ul Hassan
Jun 29 at 12:26




2 Answers
2



If you are using storyboard use this -


if let navigationObject = UIStoryboard(name: "storyboard_name", bundle: nil).instantiateViewController(withIdentifier: "viewcontroller_storyboardId") as? viewController_name {

navigationController?.pushViewController(navigationObject, animated: true)
}



You should add this first





thank u for your suggestion..! but i have use storyboard ID . this is image of my storyboard ID prnt.sc/k0qh6b
– sapna
Jun 29 at 9:38



There could be come following reasons



Check if name contains entertainment Or Entertainment as string
value? means case sensitivity(as a test do following and check)
data[indexPath.row].name.lowerCased() == "Entertainment".lowerCased()



Missing navigationController (navigation controller not embedded) if missing embed
navigationController to your root controller.



try removing dismiss(animated: true, completion: nil)


dismiss(animated: true, completion: nil)






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

Opening a url is failing in Swift

Export result set on Dbeaver to CSV