如何制作多个tableview单元格来引导相应的视图控制器? [英] How do I make multiple tableview cells to lead corresponding view controllers?

查看:22
本文介绍了如何制作多个tableview单元格来引导相应的视图控制器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个以 tableViewController 作为初始视图控制器的应用程序.它显然在 tableview 单元格中有一个项目列表.我希望每个 tableView 单元格都指向不同的 View 控制器.这是我的主屏幕的示例:![在此处输入图片说明][1]

I am making an app with a tableViewController as the initial view controller. It obviously has a list of items in tableview cells. I want each of the tableView cell to lead to a different View controller. Here is an example of my home screen: ![enter image description here][1]

例如,我想要实现的是,工具单元会将我带到包含有关工具的详细信息的视图控制器.当我点击武器时,它应该带我到一个视图控制器,其中包含有关武器的详细信息.我已经设置了视图控制器,但我不知道如何为每个视图控制器创建转场.注意:我在代码中而不是在我的故事板中制作了这些单元格.我制作了一组项目,并使用 indexpath.row 来显示它们.

What I am trying to achieve, for example, is that the tools cell will take me to a View controller with details about tools. And when I click on weapons, it should take me to a view controller with details about weapons. I already have the view controllers set up, but I don't know how to create segues to each view controller. NOTE: I made these cells in code and not in my storyboard. I made an array of items and I used indexpath.row to display them.

感谢您的帮助!

推荐答案

不是从单个单元格连接和创建 segue,您可以从位于故事板中视图下方的 View Controller 按钮连接所有这些 segue.在这种情况下,您将有多个 segue,它们都不会单独连接到单元格.当 segue 准备好时,您可以使用此方法移动到下一个视图控制器,具体取决于从 tableView 中点击的单元格.

nstead of connecting and creating segue from individual cells, you can connect all those segues from the View Controller button, lying below your view in your storyboard. In this case, you will have multiple segues and none of them will be individually connected to cells. And when segues are ready, you can use this method for moving on to the next View Controller depending on which cell is tapped from the tableView.

[self performSegueWithIdentifier:@"yourSegue" sender:nil];

您只需检查点击了哪个单元格,然后在点击时执行适当的 Segue.

You just have to check which cell is tapped and then perform the appropriate Segue on tap.

注意故事板中查看屏幕下方显示的黄色按钮.

Look out for the yellow button as shown below your View Screen in your storyboard.

将一个segue从该按钮拖放到您要连接的视图控制器上.

Drag and drop a segue from that button onto the View Controller that you want to connect.

希望这会有所帮助.

这篇关于如何制作多个tableview单元格来引导相应的视图控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆