Life is easier with blocks but UIAlertView was built in a time before blocks. Enter BBAlertView.
With BBAlertView it’s far easier to keep code nice and simple, especially when you have multiple alert views per view controller or you need to pass around an object. For example:
- (void)renameNote:(BBNote *)note {
BBAlertView *alertView = [[BBAlertView alloc] initWithTitle:NSLocalizedString(@"Rename Note", nil) message:nil cancelButtonTitle:NSLocalizedString(@"Cancel", nil)];
[alertView setAlertViewStyle:UIAlertViewStylePlainTextInput];
[alertView addButtonWithTitle:NSLocalizedString(@"Rename", nil) clicked:^(BBAlertView *alertView) {
UITextField *nameField = [alertView textFieldAtIndex:0];
[note setName:[nameField text]];
}];
[alertView show];
}
- Download the files.
- Copy
BBAlertView.handBBAlertView.minto your project’s directory. - Drag the files into Xcode.
- Add
#import "BBAlertView.h"to your project’s prefix header, e.g.MyApp-Prefix.pch. - Enjoy!