VLCAlertView.m 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*****************************************************************************
  2. * VLCStatusLabel.m
  3. * VLC for iOS
  4. *****************************************************************************
  5. * Copyright (c) 2014-2015 VideoLAN. All rights reserved.
  6. * $Id$
  7. *
  8. * Authors: Carola Nitz <nitz.carola # googlemail.com>
  9. *
  10. * Refer to the COPYING file of the official project for license.
  11. *****************************************************************************/
  12. @interface VLCAlertView () <UIAlertViewDelegate>
  13. @end
  14. // via http://stackoverflow.com/a/10082549/928646
  15. @implementation VLCAlertView
  16. - (void)dealloc
  17. {
  18. [[NSNotificationCenter defaultCenter] removeObserver:self];
  19. }
  20. - (id)initWithTitle:(NSString *)title message:(NSString *)message cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitles:(NSArray *)otherButtonTitles {
  21. self = [self initWithTitle:title message:message delegate:self cancelButtonTitle:cancelButtonTitle otherButtonTitles:nil];
  22. if (self) {
  23. [[NSNotificationCenter defaultCenter] addObserver:self
  24. selector:@selector(appWillResignActive:)
  25. name:UIApplicationWillResignActiveNotification
  26. object:nil];
  27. for (NSString *buttonTitle in otherButtonTitles) {
  28. [self addButtonWithTitle:buttonTitle];
  29. }
  30. }
  31. return self;
  32. }
  33. - (void)appWillResignActive:(NSNotification *)aNotification
  34. {
  35. [self dismissWithClickedButtonIndex:self.cancelButtonIndex animated:NO];
  36. }
  37. - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
  38. if (self.completion) {
  39. self.completion(buttonIndex == self.cancelButtonIndex, buttonIndex);
  40. self.completion = nil;
  41. self.delegate = nil;
  42. }
  43. }
  44. - (void)show
  45. {
  46. if (self.completion)
  47. self.delegate = self;
  48. [super show];
  49. }
  50. @end