swift3 - 如何使用 tableview 将页面导航到另一个视图控制器确实选择方法
问题描述
这是我从一个 viewController 导航到另一个 viewControler 的代码,但我无法导航。data 是 rest api nsobject 数据,存储来自 rest api 的类别作为名称,娱乐是一个类别。当我点击类别时转到另一个视图控制器
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 嵌入到您的根控制器,则缺少 navigationController(未嵌入导航控制器)。
尝试删除
dismiss(animated: true, completion: nil)
推荐阅读
- sql - 从具有动态表名的各种表中进行 SQL 查询
- c# - OpenApi C# 响应链接
- javascript - ReactJs:生成随机数以显示在 Material UI 进度条中
- c++ - 从我的班级调用 Object 构造函数
- python - 查看不同dtype下的对象数组
- ios - 如何使用 Swift 找到两个三角形(3 点)之间的仿射变换
- c# - nanoFramework ESP32 使用键盘睡眠后无法唤醒
- php - php动态变量并排数组插入到数据库问题
- javascript - 在数组中的字符串中查找连续字符并替换它们
- arduino - 我的 ESP8266/NodeMCU 如何与我的 GSM 模块 SIM800L 通信?