选择 UITableViewCell 时如何进行推送 [英] How to make a push segue when a UITableViewCell is selected
问题描述
我在表格视图中有一个效果列表.我创建了一个右上角的栏按钮,它可以向另一个视图控制器推送segue,这有助于创建新的效果.现在我想向表格视图单元格添加推送segue,以便可以在添加效果视图控制器上加载效果值,并且我可以保存编辑的值.
I have a list of effects in a table view. I have created a top right bar button which does a push segue to another view controller which helps create a new effect. Now I want to add push segues to the table view cells so that the effects values maybe loaded on the add effects view controller and I can save the edited values.
问题是我可以以编程方式创建推送转场吗?如果不是,我可以通过 prepareforsegue
传递效果吗?如果我尝试使用 prepareforsegue
,我会遇到一个问题,即从 UITableView
拖动控件无法让我创建一个推segue 到添加效果视图控制器.>
The question is can I create a push segue programmatically? If not can I pass the effect through a prepareforsegue
? If I try to use a prepareforsegue
, I run into a problem where control dragging from the UITableView
does not let me create a push segue to the add effects view controller.
推荐答案
control从视图控制器拖到视图控制器
control drag From View Controller to View Controller
您需要为您的转场提供一个标识符:
You will need to give an identifier to your segue:
执行转场:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self performSegueWithIdentifier:@"yourSegue" sender:self];
}
现在是这样,如果您需要将一些数据传递给该视图控制器,这将只执行转场.然后你必须实现以下 segue 委托:
Now here is the thing, this will just perform the segue, if you ever needed to pass some data to that view controller. Then you have to implement the following segue delegate:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Make sure your segue name in storyboard is the same as this line
if ([[segue identifier] isEqualToString:@"yourSegue"])
{
//if you need to pass data to the next controller do it here
}
}
这篇关于选择 UITableViewCell 时如何进行推送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!