[英]How to navigate to another view controller in the same tab of the tab bar controller in swift 3?
[英]How to navigate a page into another view controller using tableview did select method
这是我从一个viewController导航到另一个viewControler的代码,但是我无法导航。 数据是rest api nsobject数据,它存储来自rest api的类别作为名称,娱乐是类别。 当我点击类别时转到另一个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..!")
}
}
可能有以下原因
检查名称是否包含娱乐性或娱乐性作为字符串值? 表示区分大小写(作为测试,然后进行检查)data [indexPath.row] .name.lowerCased()==“ Entertainment” .lowerCased()
如果缺少,则缺少navigationController(未嵌入导航控制器),将embeding Controller嵌入到根控制器中。
尝试删除dismiss(animated: true, completion: nil)
只需使用此
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)
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.