VLCAlertView.m 1.84 KB
Newer Older
1 2 3 4
/*****************************************************************************
 * VLCStatusLabel.m
 * VLC for iOS
 *****************************************************************************
5
 * Copyright (c) 2014-2015 VideoLAN. All rights reserved.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
 * $Id$
 *
 * Authors: Carola Nitz <nitz.carola # googlemail.com>
 *
 * Refer to the COPYING file of the official project for license.
 *****************************************************************************/

@interface VLCAlertView () <UIAlertViewDelegate>

@end

// via http://stackoverflow.com/a/10082549/928646

@implementation VLCAlertView

- (id)initWithTitle:(NSString *)title message:(NSString *)message cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitles:(NSArray *)otherButtonTitles {

    self = [self initWithTitle:title message:message delegate:self cancelButtonTitle:cancelButtonTitle otherButtonTitles:nil];

    if (self) {
26 27 28 29
        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(appWillResignActive:)
                                                     name:UIApplicationWillResignActiveNotification
                                                   object:nil];
30 31 32 33 34 35 36
        for (NSString *buttonTitle in otherButtonTitles) {
            [self addButtonWithTitle:buttonTitle];
        }
    }
    return self;
}

37 38 39 40 41
- (void)appWillResignActive:(NSNotification *)aNotification
{
    [self dismissWithClickedButtonIndex:self.cancelButtonIndex animated:NO];
}

42 43 44 45
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
    if (self.completion) {
        self.completion(buttonIndex == self.cancelButtonIndex, buttonIndex);
        self.completion = nil;
46
        self.delegate = nil;
47 48 49
    }
}

50 51 52 53 54 55 56 57
- (void)show
{
    if (self.completion)
        self.delegate = self;

    [super show];
}

58
@end