How to call presentViewController?

坚强是说给别人听的谎言 提交于 2019-12-11 06:23:41

问题


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):

[self presentViewController:myViewController animated:YES];

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

Thanks in advance.


回答1:


You call the method on the UIViewController that is your MainView, and pass it your UIViewController you want to be the ActionSheet.

[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];

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



来源:https://stackoverflow.com/questions/6331771/how-to-call-presentviewcontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!