0

I have a selector to show UIAlertView asking user if want to retry upload images after NotificationCenter post a notification with observename.

[[NSNotificationCenter defaultCenter] postNotificationName:kNOTIFICATION_PHOTOS_UPLOAD_RETRY object:nil];

But because of the notification received more than one, so will show as many as notifications received. Is there a best practice to show alert view only once?

Edward Chiang
  • 1,133
  • 2
  • 12
  • 24

1 Answers1

0

Yeah, you can do something like:

@interface MyClass
{
    UIAlertView *_myAlertView;
}
@end

@implementation MyClass
...
- (void)myNotificationSelector:(NSNotification *)notification
{
    if (!_myAlertView) {
        _myAlertView = [[UIAlertView alloc] init ...]
        _myAlertView.delegate = self;
        [_myAlertView show];
    }
}
...
@end

and in the UIAlertViewDelegate handlers, just release and set _myAlertView to NO.

pho0
  • 1,751
  • 16
  • 24
  • Thanks! But I found out that I addObserver to the same name `kNOTIFICATION_PHOTOS_UPLOAD_RETRY` in the parent, and alloc/init too many extend classes, cause too many UIViewController display the UIAlertView. So I use your advise and make sure only addObserver to one class. – Edward Chiang Oct 16 '12 at 10:04