ryanmaxwell / UIAlertView-Blocks

Category on UIAlertView to use inline block callbacks instead of delegate callbacks.
MIT License
425 stars 58 forks source link

Bug: not passing an otherButtonTitle in the UIAlertView init method mean... #5

Closed karlvr closed 10 years ago

karlvr commented 10 years ago

...s firstOtherButtonIndex isn't set correctly!

So I've modified the creation of the UIAlertView so it passes the first other button title and then adds any additional ones separately.

ryanmaxwell commented 10 years ago

Yeah you're right, first other button index will be -1, and a cancel will be at 0.

The following causes a crash!

[UIAlertView showWithTitle:@"Title"
                       message:@"Message"
             cancelButtonTitle:@"cancel"
             otherButtonTitles:@[@"one", @"two"]
                      tapBlock:^(UIAlertView *alertView, NSInteger buttonIndex){
        NSLog(@"%@", [alertView buttonTitleAtIndex:alertView.firstOtherButtonIndex]);
    }];

I like your sneaky workaround!