天天看点

6.UIAlertView的基本使用

1.输入文字的alertView

  • alertView 可以选择样式,有弹出让用户输入文字的样式以及怎么获得alertView上的UITextField:

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"修改数据" message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil]; alert.alertViewStyle = UIAlertViewStylePlainTextInput; UITextField *textField = [alert textFieldAtIndex:0]; //textField.text =hero.name; textField.placeholder=hero.name; [alert show];

  • 通过代理拿到文字

    - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ UITextField *textField = [alertView textFieldAtIndex:0]; NSString *newStr = textField.text; }