1

I have showed an alert view locally in an function call like this...

        UIAlertView *alert_local = [[UIAlertView alloc]
                                    initWithTitle:nil
                                    message:@"Are you sure want to discard what you have recorded so far?"
                                    delegate:self cancelButtonTitle:@"Yes"
                                    otherButtonTitles:@"No", nil];
        alert_local.tag = 4;
        [alert_local show];

But I have not responded YES or NO for that. And In a sequence I have popped the view which is showing the alert from outside, but alert view remains, I have handled it by making the alert view as ivar. Is this the correct approach? or Any other way to handle this kind of sequence? Why the alert view remains after its parent view is popped?

Newbee
  • 3,231
  • 7
  • 42
  • 74

2 Answers2

3

Yes, if a view controller shows an alert view it is responsible of removing the alert.

It the view controller can disappear by some event not triggered by the user it has to make sure that the alert view is dismissed. So storing it in an ivar seems appropriate. I use a weak ivar for this as it is not necessary to retain the view when it's gone.

Nikolai Ruhe
  • 81,520
  • 17
  • 180
  • 200
0

try this by adding below line in viewWillDisappear

 [alert_local dismissWithClickedButtonIndex:alert_local.cancelButtonIndex animated:YES];    

Note:- declare your UIAlertView in .h file

Aman Aggarwal
  • 3,754
  • 1
  • 19
  • 26
  • Ya I did like that already, Any other approach to dismiss automatically when its parent view disappears. – Newbee Feb 27 '13 at 12:19