选择UITableViewCell时如何进行推送segue [英] How to make a push segue when a UITableViewCell is selected

查看:129
本文介绍了选择UITableViewCell时如何进行推送segue的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在表格视图中有一个效果列表。我创建了一个右上角的条形按钮,可以将一个推送到另一个视图控制器,这有助于创建一个新的效果。现在我想将push segues添加到表格视图单元格中,以便可以在添加效果视图控制器上加载效果值,我可以保存已编辑的值。

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.

问题我可以通过编程方式创建push segue吗?如果没有,我可以通过 prepareforsegue 传递效果吗?如果我尝试使用 prepareforsegue ,我遇到一个问题,从 UITableView 中拖出控件不会让我创建推送到添加效果视图控制器。

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

您需要为您的segue提供一个标识符:

You will need to give an identifier to your segue:

执行segue:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self performSegueWithIdentifier:@"yourSegue" sender:self];
}

现在就是这件事,如果你做的话,这只会执行segue需要将一些数据传递给该视图控制器。然后你必须实现以下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时如何进行推送segue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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