0

Im setting an MaxIdleTime in my app once if no userInteraction happened within this specified time i'm just removing the existing view from my window and adding my login (Home) view as subview to my apps UIWindow through a method called logout. In this logout i'm just removing all the references which are alive but if any of the UIPopOverController is visible on any view during this logout call i'm getting exception

-[UIPopoverController dealloc] reached while popover is still visible.

Im making popover instance to nil in viewDidUnload even though i'm getting this exception and app is crashing and my project is ARC enabled. How to overcome this exception, any help is appreciated in advance.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Graham Bell
  • 1,139
  • 1
  • 14
  • 30
  • So you're trying to remove all subviews in the current view as soon as the timer fires? – The Kraken May 16 '13 at 15:36
  • @TheKraken exactly and btw my logout method definition is in some rootClass and my popovers are there in different classes, but when ever the timer fire its selector method is this logOut method, so here i need to remove all subviews. – Graham Bell May 16 '13 at 15:40

1 Answers1

0

To remove all the subviews in your main view when the timer fires, use the following code:

for (UIView *sub in [[_view subviews] copy]) {
    [sub removeFromSuperView];
    sub = nil;
}

As for the popovers, simply remove the one currently onscreen with:

[pop dismissPopoverAnimated:NO];
pop = nil;
The Kraken
  • 3,158
  • 5
  • 30
  • 67
  • 1
    Only one popover can be visible at any given time so there is no need for an array. Also note that your `for` code would trigger an exception because you are modifying arrays while enumerating them. A `copy` call is neccessary, e.g. `for (UIView* sub in [[_view subview] copy])` – Sulthan May 16 '13 at 15:48