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.

Dylan Gattey
  • 1,713
  • 13
  • 34

2 Answers2

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.

Robin
  • 10,011
  • 5
  • 49
  • 75
  • 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. – Dylan Gattey Jun 12 '11 at 21:29
3

try to dismiss in applicationDidBecomeActive method of appDelegate.

Hiren
  • 12,720
  • 7
  • 52
  • 72
Rahul Vyas
  • 28,260
  • 49
  • 182
  • 256
  • 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. – Rahul Vyas Jun 12 '11 at 03:38
  • make sure you have access to your action sheet instance – Rahul Vyas Jun 12 '11 at 03:39
  • 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? – Dylan Gattey Jun 12 '11 at 05:20
  • 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. – Rahul Vyas Jun 12 '11 at 05:44
  • From a view controller. I'll send it over. Thanks so much. – Dylan Gattey Jun 12 '11 at 05:54
  • ok.I'll look into the issue right now and will update you back – Rahul Vyas Jun 12 '11 at 05:58
  • Ok, download the code at http://bit.ly/ifbuOH, http://bit.ly/kDEEH3, http://bit.ly/iNxPt8, and http://bit.ly/mTVYGh. Thanks again. – Dylan Gattey Jun 12 '11 at 06:07
  • 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. – Rahul Vyas Jun 12 '11 at 06:12
  • 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? – Dylan Gattey Jun 12 '11 at 06:26
  • 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. – Rahul Vyas Jun 12 '11 at 12:16
  • 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 works – Rahul Vyas Jun 12 '11 at 12:17
  • Thanks for trying. Robin's answer worked for me. She basically had the same approach as your first answer just now. – Dylan Gattey Jun 12 '11 at 21:30
  • @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? – Rahul Vyas Jun 13 '11 at 01:49
  • 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 skicrazy27@live.com. 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. – Dylan Gattey Jun 13 '11 at 03:37