How do you dismiss a UIActionSheet from the App Delegate?
Asked Answered
S

2

5

I'm trying to dismiss a UIActionSheet from the app delegate so that it doesn't show again when you return from background. I've tried to dismiss the action sheet from the viewDidUnload or viewDidDisappear methods in the subclass view controller, but that doesn't seem to get called when the app backgrounds.

Therefore, I'm trying to use the app delegate to dismiss either UIActionSheet that may be showing when the app backgrounds. But I can't figure out what to call. Does anyone have a solution? Or a better idea to accomplish the same thing?

Thanks.

Saber answered 12/6, 2011 at 2:51 Comment(4)
You can dismiss your actionSheet in viewWillAppear method insteadAnalogue
That doesn't work either. Nor viewDidAppear.Saber
tell me something do you have that UIActionSheet object as an instance variable of your class or notAnalogue
Yes, I do, but how do I grab that variable from the app delegate?Saber
A
4

@Dylan what you can do is you can declare the property for your uiactionsheet variable and also synthesis it.

Then in appdelegate in applicationDidBecomeActive method you can dismiss that actionsheet by calling the dismiss method by doing something like this [viewController.actionSheet dismissWithClickedButtonIndex:0 animated:NO]. Assuming that you have the reference in your appdelegate.

But if not then you can find all the UIViews shown on top of the uiwindow and then check if any of the uiviews is kind of class that is showing actionsheet. After that you can dismiss the actionsheet by doing the same as written above once you have the hold of that viewController that is showing actionsheet.

Analogue answered 12/6, 2011 at 15:0 Comment(1)
Thank you! Worked perfectly! I just found the viewController that had an actionsheet showing, like you said, and dismissed it by doing actionSheetCancel. I appreciate it.Saber
A
3

try to dismiss in applicationDidBecomeActive method of appDelegate.

Ardeha answered 12/6, 2011 at 2:56 Comment(14)
Read UIActionSheet Class Refrence here is the method // hides alert sheet or popup. use this method when you need to explicitly dismiss the alert. // it does not need to be called if the user presses on a button - (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated Call this method by your actionSheet object.Ardeha
make sure you have access to your action sheet instanceArdeha
How would I call that? And how do I get access? The problem is, I know how to use dismissWithClickedButtonIndex and actionSheetCancel (easier to use) but I can't get access to my action sheet from the app delegate. If I could, that would be the easy answer. Any thoughts on how to do that?Saber
From Where is your action sheet displayed? from a viewController or from AppDelegate? if you can send your code I'll look into the issue.Ardeha
From a view controller. I'll send it over. Thanks so much.Saber
ok.I'll look into the issue right now and will update you backArdeha
Ok, download the code at bit.ly/ifbuOH, bit.ly/kDEEH3, bit.ly/iNxPt8, and bit.ly/mTVYGh. Thanks again.Saber
Please send complete xcodeProject remove your confidential files just these 4 classes. I mean a running demo so that it's easier to fix the issue.Ardeha
It's much too complicated. I have about 50 class files plus loads of images, etc. A lot of it is also confidential. All I want to do is dismiss an action sheet that's called from the landscapeMapController (as you can see) from the FPPDX App Delegate. Possible?Saber
No because with these 4 classes code won't run. Try iterating through viewControllers of tabbar and then get the viewController which has actionsheet (assume you have created property of action sheet) then try to dismiss the action and see if it works.Ardeha
Ok I have another approach. You can use a notification for dismissing action sheet. Raise the notification when app enters in background.Try and let me know if it worksArdeha
Thanks for trying. Robin's answer worked for me. She basically had the same approach as your first answer just now.Saber
@Dylan G Happy Coding :-). By the way which app you are creating and in the past have you created some apps. I would like to know the names of the apps. Also what is your mail address?Ardeha
Thanks! I'm creating Forest Park PDX. Should be up on the App Store within the month. It's my first app, but I hope to have another, Find Tune It, up within the year. My email is [email protected]. Email me there and I'll give you a better email to use. I just don't want to say my real one here. Thanks again for the help.Saber

© 2022 - 2024 — McMap. All rights reserved.