简体   繁体   English

iOS tableview单元格segue故事板

[英]iOS tableview cell segue storyboard

I am currently implementing a simple fitness app. 我目前正在实施一个简单的健身应用程序。

I have each exercises for each tableviewcell row and when i click each tableviewcell, I want to segue it to tutorial screen where it shows short clip of video. 我对每个tableviewcell行都有每个练习,当我单击每个tableviewcell时,我想将其搜索到教程屏幕,其中显示了视频的短片。

My question is; 我的问题是;

If I have 100 different exercises, do i need to created 100 different segue for each exercises? 如果我有100个不同的练习,是否需要为每个练习创建100个不同的练习?

and how do I make different tableviewcells to segue into same view? 以及如何使不同的tableviewcell接合到同一视图?

You asked "If I have 100 different exercises, do i need to created 100 different segues..." 您问“如果我有100种不同的练习,是否需要创建100种不同的练习...”

In a word, no. 一言以蔽之。

You could create a single view controller to view controller segue and give it an identifier. 您可以创建一个视图控制器来查看控制器序列并为其指定标识符。

Implement the tableView:didSelectRowAtIndexPath: method. 实现tableView:didSelectRowAtIndexPath:方法。 In that method, save the selected indexPath to an instance variable and call performSegueWithIdentifier to invoke your segue. 在该方法中,将选定的indexPath保存到实例变量,然后调用performSegueWithIdentifier来调用您的segue。

In your prepareForSegue method, take the selected cell's indexPath and use it to look up the data for that cell. 在您的prepareForSegue方法中,采用所选单元格的indexPath并使用它来查找该单元格的数据。 Cast the segue's destination view controller to the correct class, and then set a property you've defined in the destination view controller to the data you want to display for the selected cell (information about the selected exercise, in this case.) 将segue的目标视图控制器转换为正确的类,然后将在目标视图控制器中定义的属性设置为要为选定单元格显示的数据(在这种情况下,有关选定练习的信息)。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM