Skip to content

Instantly share code, notes, and snippets.

@icodebuster
Created November 21, 2013 04:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save icodebuster/7576262 to your computer and use it in GitHub Desktop.
Save icodebuster/7576262 to your computer and use it in GitHub Desktop.
UIAlertView-Blocks taking input https://github.com/ryanmaxwell/UIAlertView-Blocks
- (IBAction)btnTouchEvent:(id)sender
{
__block NSString *str;
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Rename" message:@"Enter new file name" delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
alert.delegate = alert;
[alert setAlertViewStyle:UIAlertViewStylePlainTextInput];
alert.shouldEnableFirstOtherButtonBlock = ^BOOL(UIAlertView *alertView) {
str = [[alertView textFieldAtIndex:0].text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
return ([str length] > 0);
};
// When tapped on the other button
[alert setTapBlock:^(UIAlertView *alertView, NSInteger buttonIndex) {
if (buttonIndex != [alertView cancelButtonIndex]) {
NSLog(@"String = %@", str);
}
}];
[alert show];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment