【问题标题】:How do I present a modal view upon an option in UIActionSheet being tapped?如何在点击 UIActionSheet 中的选项时呈现模式视图?
【发布时间】:2013-03-06 21:43:36
【问题描述】:

我有我的主视图控制器,点击一个按钮会弹出一个操作表。我想要点击其中的一个选项来显示一个操作表。然而,尽管我进行了所有的搜索,我似乎无法弄清楚。

我有以下代码:

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

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

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

【问题讨论】:

    标签: ios objective-c ios5 ios6 storyboard


    【解决方案1】:

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

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

    注意

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

    故事板法

    首先在 Storyboards 中单击您的 segue,然后在信息面板中为其指定一个标识符。

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

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

    【讨论】:

    • 我将如何在我的情节提要中执行后面的解决方案?
    • 首先我得到这个错误:No visible @interface for 'RootViewController' declares the selector 'presentViewController:animated:'
    • @DougSmith 那是因为presentViewController:animated: 不存在,实际上是presentViewController:animated:completion: 我已经编辑了帖子以反映这一点。
    • 抱歉错字。谢谢@0x7fffffff
    • @DougSmith 我添加了有关使用 Storyboard + Segue 方法的信息。
    猜你喜欢
    • 2012-10-15
    • 2015-12-11
    • 1970-01-01
    • 1970-01-01
    • 2023-02-22
    • 1970-01-01
    • 2015-07-05
    • 2011-10-17
    • 1970-01-01
    相关资源
    最近更新 更多