天天看點

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; }