Alert view with text input

Send Snippet To: Save this snippet to Code Collector Pro -- view all balzan's snippets
language: Objective-C
license: Other

Code for Snippet:

                
// in view controllers .h file
 
add delegate UIAlertViewDelegate
 
 
 
// in .M file
 
 
 UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"New Tag" message:@"Type the show your looking for" delegate:self cancelButtonTitle:@"Search" otherButtonTitles:nil];
            alert.alertViewStyle = UIAlertViewStylePlainTextInput;
			//alert.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput
 
            UITextField * alertTextField = [alert textFieldAtIndex:0];
            alertTextField.keyboardType = UIKeyboardTypeDefault;
            alertTextField.placeholder = @"Show name";
            [alert show];
 
 
// then later this will be called
 
#pragma mark - UIalertView Delegate
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
 
    if (alertView.cancelButtonIndex != buttonIndex) {
		if ([alertView.title isEqualToString:@"New Group"]) {
			// check input long enought
			NSString* text = [alertView textFieldAtIndex:0].text;
			if (text.length > 1){
				[self performSegueWithIdentifier:@"" sender:text];
			}
		}
 
	}
}
comments powered by Disqus

Info

Link to this snippet:


Download to Code Collector

To use the direct link to your snippet on CodeCollector.net either copy the html from the above section or drag the Download to Code Collector to where you would like to use it.

More Info:

Times Viewed: 347
Date Added: 2012-06-09 11:04:58
Last Modified: 2014-02-18 20:29:30

Web Analytics