Created
November 21, 2013 04:52
-
-
Save icodebuster/7576262 to your computer and use it in GitHub Desktop.
UIAlertView-Blocks taking input https://github.com/ryanmaxwell/UIAlertView-Blocks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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