ios 如何调用presentViewController?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6331771/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 20:20:39  来源:igfitidea点击:

How to call presentViewController?

iosuiviewcontrolleruiactionsheetpresentmodalviewcontroller

提问by Gary

Here is the situation: I have a class MainView (which is a UIViewController) and call from it an UIActionSheetDelegate class. I want to use the method presentViewController, but the following code does not work (currently being called in the ActionSheet class):

这是情况:我有一个类 MainView(它是一个 UIViewController)并从中调用一个 UIActionSheetDelegate 类。我想使用presentViewController方法,但是下面的代码不起作用(当前在ActionSheet类中被调用):

[self presentViewController:myViewController animated:YES];

I am a little confused regarding where I should call the method from (MainView or the ActionSheetDelegate).

我对应该从哪里调用方法(MainView 或 ActionSheetDelegate)感到有些困惑。

Thanks in advance.

提前致谢。

回答by Jesse Naugher

You call the method onthe UIViewController that is your MainView, and passit your UIViewController you want to be the ActionSheet.

作为您的 MainView 的 UIViewController调用该方法,并将您希望成为 ActionSheet 的 UIViewController传递给它。

[mainViewController presentViewController:actionSheetController animated:YES];

To dismiss the UIActionSheet, dimissWithClickedButtonIndex:animated:is a method for the UIActionSheet that you can implement. The method can be called by whoever (so if you want to dismiss it from your mainview have a reference to the action sheet and do something like [self.myActionSheet dismissWithClickedButtonIndex:0 animated:YES];

要关闭 UIActionSheet,dimissWithClickedButtonIndex:animated:是您可以实现的 UIActionSheet 方法。该方法可以由任何人调用(因此,如果您想从主视图中关闭它,请参考操作表并执行类似的操作[self.myActionSheet dismissWithClickedButtonIndex:0 animated:YES];

The method is also called whenever the 'cancel' button is clicked by the user.

每当用户单击“取消”按钮时,也会调用该方法。