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..!")
}
}
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)
Simply Use This,
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
{
if data[indexPath.row].name == "Entertainment" {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let whiteVC = storyboard.instantiateViewController(withIdentifier: "WhiteViewController") as! WhiteViewController
self.navigationController?.pushViewController(whiteVC, animated: true)
}
}
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.