How to call presentViewController?

2019-08-02 06:12发布

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条回答
该账号已被封号
2楼-- · 2019-08-02 06:52

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.

查看更多
登录 后发表回答