Skip to content

Instantly share code, notes, and snippets.

@keicoder
Created February 25, 2014 05:21
Show Gist options
  • Save keicoder/9203199 to your computer and use it in GitHub Desktop.
Save keicoder/9203199 to your computer and use it in GitHub Desktop.
oobjective-c : UIAlertView 텍스트 입력 받기
//UIAlertView 텍스트 입력 받기
//TWAlbumTableViewController.h
@interface TWAlbumTableViewController : UITableViewController
@property (strong, nonatomic) NSMutableArray *albums;
- (IBAction)addAlbumBarButtonPressed:(UIBarButtonItem *)sender;
@end
//TWAlbumTableViewController.m
@interface TWAlbumTableViewController () <UIAlertViewDelegate> //alertView 델리게이트
- (IBAction)addAlbumBarButtonPressed:(UIBarButtonItem *)sender
{
UIAlertView *newAlbumAlertView = [[UIAlertView alloc] initWithTitle:@"Enter New Album Name"
message:nil
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Add", nil];
[newAlbumAlertView setAlertViewStyle:UIAlertViewStylePlainTextInput]; //alertView 스타일 지정
[newAlbumAlertView show];
}
#pragma mark - UIAlertView 델리게이트
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (debug==1) {NSLog(@"Running %@ '%@'", self.class, NSStringFromSelector(_cmd));}
if (buttonIndex == 1) {
//textFieldAtIndex:0 - alertView 스타일을 UIAlertViewStylePlainTextInput으로 지정 했음
NSString *alertText = [alertView textFieldAtIndex:0].text;
NSLog (@"My new album is %@", alertText);
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment