简体   繁体   English

如何在点击UIActionSheet中的选项时显示模式视图?

[英]How do I present a modal view upon an option in UIActionSheet being tapped?

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. 尽管进行了所有搜索,但我似乎无法弄清楚。

I have the following code: 我有以下代码:

- (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];
}

Note 注意

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. 两者的工作原理相同。

Storyboard Method 故事板方法

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. 然后,您可以用此代码替换代码,它应该触发情节提要中的segue。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在UICollectionView中点击时如何将图像扩展为完整视图? - How do I expand image to full view when being tapped in a UICollectionView? 如何在UIActionSheet中显示UIImagePickerViewController? - How can I present UIImagePickerViewController in UIActionSheet? 如何在没有任何动画的情况下直接将模态视图呈现为表单 - How do I present modal view as form sheet directly without any animation 如何在我的标签栏iOS应用程序上显示模态UINavigation视图? - How do I present a modal UINavigation view over my tab bar iOS app? 如何让从 Firestore 检索的文本加载到显示的视图上? - How do I let text retrieved from Firestore load upon the view being shown? 我在一个视图控制器上有两个 TableView,如何根据点击的 TableView 将数据传递给单独的视图控制器? - I have two TableViews on a single View Controller, how can I pass data to a separate View Controller based upon which TableView was tapped? 如何在“ parentViewController”中显示模式视图? - How to present modal view in “parentViewController”? "如何在 Swift 中呈现 iOS UIActionSheet?" - How to present iOS UIActionSheet in Swift? 如果调出UIActionSheet,如何使其中一个选项适合新视图? - If I bring up a UIActionSheet, how do I make one of the options segue to a new view? 点击文本字段时如何显示视图控制器? - How to present a view controller when a text field is tapped?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM