简体   繁体   English

如何使用tableview将页面导航到另一个视图控制器中并选择了方法

[英]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. 这是我从一个viewController导航到另一个viewControler的代码,但是我无法导航。 data is rest api nsobject data that stored category from rest api as name, entertainment is a category . 数据是rest api nsobject数据,它存储来自rest api的类别作为名称,娱乐是类别。 when i tap on category goto another viewController 当我点击类别时转到另一个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..!")
    }
}

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)
            }

您应该先添加

There could be come following reasons 可能有以下原因

  1. 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() 表示区分大小写(作为测试,然后进行检查)data [indexPath.row] .name.lowerCased()==“ Entertainment” .lowerCased()

  2. Missing navigationController (navigation controller not embedded) if missing embed navigationController to your root controller. 如果缺少,则缺少navigationController(未嵌入导航控制器),将embeding Controller嵌入到根控制器中。

  3. try removing dismiss(animated: true, completion: nil) 尝试删除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)
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何导航到swift 3中标签栏控制器的同一选项卡中的另一个视图控制器? - How to navigate to another view controller in the same tab of the tab bar controller in swift 3? 成功验证后如何导航至视图控制器? - How to navigate to view controller after successful verification? 如何使用post方法从登录功能将JSON数据传递到另一个视图控制器? - How to pass JSON data to another view controller from login function using post method? 如何从另一个视图控制器调用UIPickerView子类中的方法? - How to call method in UIPickerView subclass from another view controller? 如何通过按下图像导航到另一个UIView控制器(以前在情节提要中创建) - How to navigate to another UIView controller (previously created in storyboard) by pressing an image 如何在不使用按钮的情况下从一个视图控制器移动到另一个 - how to move from one view Controller to another without using a button 如何从Rest Api加载图像到视图中使用Swift 3加载方法 - how to load image From Rest Api Into View did Load Method Using Swift 3 如何在另一个视图控制器后面显示视图控制器? - How to present view controller behind another view controller? 如何在另一个视图控制器的顶部滑动一个视图控制器? - How to swipe a View controller over the top of another view controller? 如何使用Segues从UIView导航到UIView Controller? - How to navigate from UIView to a UIView Controller using segues?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM