首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用UIActionSheetDelegate执行多个Segues

使用UIActionSheetDelegate执行多个Segues
EN

Stack Overflow用户
提问于 2014-06-09 20:13:15
回答 1查看 54关注 0票数 2

我希望通过一个UIBarButtonItem按钮拥有多个segue,根据通过UIActionSheetDelegate的响应,正确的UIViewController将通过push segue加载。这是我当前的UIActionSheetDelegate代码。

代码语言:javascript
复制
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 0)
    {
        // rate this app
    }

    else if (buttonIndex == 1)
    {
        [self performSegueWithIdentifier:@"bugReportSegue" sender:self];
    }

    else if (buttonIndex == 2)
    {
        [self performSegueWithIdentifier:@"featureRequestSegue" sender:self];
    }
}

这方面的问题是,我不能链接同一按钮到多个视图通过故事板塞格。我想知道是否有解决办法。

编辑

这就是我的代码现在的样子:(减去故事板)

代码语言:javascript
复制
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 0)
    {
        // rate this app
    }

    else if (buttonIndex == 1)
    {
        [self.storyboard instantiateViewControllerWithIdentifier:@"bugReportIdentifier"];
    }

    else if (buttonIndex == 2)
    {
        [self.storyboard instantiateViewControllerWithIdentifier:@"featureRequestIdentifier"];
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-06-09 20:21:39

而不是将segueperformSegueWithIdentifier结合使用

考虑将StoryboardIDinstantiateViewControllerWithIdentifier:一起使用

要做到这一点,在Storyboard中,只需创建一个视图控制器就可以了,并且不要将任何分支连接到它。在属性检查器的第三个选项卡中,为它分配一个Storyboard ID

然后,在代码中,您可以创建如下所示的实例:

[self.storyboard instantiateViewControllerWithIdentifier:@"ImagePicker"]

这将在每次创建一个新实例,所以您仍然应该保存它,并在可能的情况下重用它。

编辑:在您获得视图控制器之后,您需要自己展示它。

如果您使用的是NavigationViewController调用:

代码语言:javascript
复制
UIViewController * newController = [self.storyboard instantiateViewControllerWithIdentifier:@"ImagePicker"];
[self.navigationController pushViewController:newController];

如果没有,您可以使用:

代码语言:javascript
复制
UIViewController * newController = [self.storyboard instantiateViewControllerWithIdentifier:@"ImagePicker"];
[self presentViewController:newController animated:YES completion:nil];

编辑2:下面是您的最终代码应该是什么样子:

代码语言:javascript
复制
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 0)
    {
        // rate this app
    }

    else if (buttonIndex == 1)
    {
        UIViewController * controller = [self.storyboard instantiateViewControllerWithIdentifier:@"bugReportIdentifier"];
        [self presentViewController:controller animated:YES completion:nil];
    }

    else if (buttonIndex == 2)
    {
        UIViewController * controller = [self.storyboard instantiateViewControllerWithIdentifier:@"bugReportIdentifier"];
        [self presentViewController:controller animated:YES completion:nil];
    }
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24128201

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档