私は3つのUITextFieldでUIAlertViewを作成しました。どのように私はUIAlertViewのアクションを得ることができます。 clickedButtonAtIndexデリゲートメソッドが機能しています。UIAlertViewで3 UITextFieldを作成しましたが、動作しません。
しかし、フィールドに入力されたテキストを取得できません。何か案が ?ありがとうございます。デリゲートで
UIView *v_alert = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 250, 100)];
v_alert.tag=10;
UITextField *textField1 = [[UITextField alloc] initWithFrame:CGRectMake(10,0,252,25)];
textField1.borderStyle = UITextBorderStyleRoundedRect;
textField1.placeholder = @"Your Previous Password";
textField1.keyboardAppearance = UIKeyboardAppearanceAlert;
textField1.delegate = self;
textField1.tag=1;
[v_alert addSubview:textField1];
UITextField *textField2 = [[UITextField alloc] initWithFrame:CGRectMake(10,30,252,25)];
textField2.placeholder = @"Your New Password";
textField2.borderStyle = UITextBorderStyleRoundedRect;
textField2.keyboardAppearance = UIKeyboardAppearanceAlert;
textField2.delegate = self;
textField2.tag=2;
[v_alert addSubview:textField2];
UITextField *textField3 = [[UITextField alloc] initWithFrame:CGRectMake(10,60,252,25)];
textField3.placeholder = @"Email";
textField3.borderStyle = UITextBorderStyleRoundedRect;
textField3.keyboardAppearance = UIKeyboardAppearanceAlert;
textField3.delegate = self;
textField3.tag=3;
[v_alert addSubview:textField3];
alertV = [[UIAlertView alloc] initWithTitle:@"Change Password" message:@"" delegate:self cancelButtonTitle:@"NO" otherButtonTitles:@"YES", nil];
[alertV setValue:v_alert forKey:@"accessoryView"];
alertV.tag==100;
alertV.delegate=self;
[alertV show];
は:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLog(@"didDismissWithButtonIndex");
UITextField*txt1=[[[self.view viewWithTag:100] viewWithTag:10] viewWithTag:0];
UITextField*txt2= [[[self.view viewWithTag:100] viewWithTag:10] viewWithTag:1];
UITextField*txt3= [[[self.view viewWithTag:100] viewWithTag:10] viewWithTag:2];
NSLog(@"%@--%@--%@",txt1.text,txt2.text,txt3.text);
}
そして
alertV.delegate = self; –
最初に表示されたアラートビューは、iOS 8で廃止されました。 – user3182143
@ user3182143が正しいです。もしiOS8以上で作業しているのなら、 'UIAlertController'を使用する必要があります。 – Kampai