如何在UIActionSheet中选项中显示模态视图? [英] How do I present a modal view upon an option in UIActionSheet being tapped?

查看:147
本文介绍了如何在UIActionSheet中选项中显示模态视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的主视图控制器,点击按钮会显示一个操作表。我想在那里点击其中一个选项以显示一个操作表。尽管如此,我似乎无法弄明白。

I have my main view controller, and tapping a button brings up an action sheet. I want one of the options tapped there to bring up an action sheet. I can't seem to figure it out, however, despite all my searching.

我有以下代码:

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    NSString *buttonTitle = [actionSheet buttonTitleAtIndex:buttonIndex];

    if ([buttonTitle isEqualToString:@"Text"]) {
        AddTextViewController *addTextViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"addTextViewController"];        
    }

现在我实例化了视图控制器,我不知道该怎么做。

Now that I instantiated the view controller, I don't know what to do.

推荐答案

在实例化之后立即添加此行。

Add this line right after you instantiate it.

if ([buttonTitle isEqualToString:@"Text"]) {
    AddTextViewController *addTextViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"addTextViewController"];        
    [self presentViewController:addTextViewController animated:YES completion:nil];
}

注意

您还可以在Storyboard中创建一个自定义segue来显示您的视图,然后您可以只执行自定义segue,而不是实例化和呈现。两者的工作原理相同。

You can also create a custom segue in the Storyboard that presents your view, then instead of instantiating and presenting you can just perform your custom segue. Both work the same.

故事板方法

首先在故事板中点击你的segue ,然后在信息面板中给它一个标识符。

First click your segue in Storyboards, then give it an identifier in the info panel.

然后你可以用这个替换你的代码,它应该触发你的故事板中的segue。

Then you can replace your code with this and it should trigger the segue from your Storyboard.

if ([buttonTitle isEqualToString:@"Text"]) {
    [self performSegueWithIdentifier:@"infoSegue" sender:self];
}

这篇关于如何在UIActionSheet中选项中显示模态视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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