UITextField in UIAlertView on iPhone - how to make it responsive?

前端 未结 10 1377
情歌与酒
情歌与酒 2020-11-28 05:27

I placed a UITextField into a UIAlertView and moved it up so the keyboard wouldn\'t cover it up with the following code:

[dialog setDelegate:self];
[dialog s         


        
10条回答
  •  温柔的废话
    2020-11-28 05:41

    This is for iOS5 and ARC.

    -(void)showAlert {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"New Album" 
            message:@"Enter a name for the album." 
            delegate:self 
            cancelButtonTitle:@"Cancel" 
            otherButtonTitles:@"Save", nil];
        alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
    
        UITextField* textfield = [alertView textFieldAtIndex:0];
        textfield.placeholder = @"Title";
    
        [alertView show];
    }
    
    -(void)alertView:(UIAlertView *)alertView 
        didDismissWithButtonIndex:(NSInteger)buttonIndex 
    {
        if (buttonIndex != 1) {
            NSLog(@"Cancel");
            return;
        }
        UITextField* textfield = [alertView textFieldAtIndex:0];
        NSLog(@"Save. text: %@", textfield.text);
    }
    

提交回复
热议问题