【发布时间】:2015-03-27 08:07:52
【问题描述】:
伙计们,我刚刚创建了一个alertview,在子视图中有 3 个字段,如下所示:
//----adding an alertview----
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Vehicle Information" message:@"" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Add", nil];
CGRect frame = CGRectMake(0, 0, self.view.frame.size.width, 300);
UIView *view = [[UIView alloc] initWithFrame:frame];
UITextField* text1 = [[UITextField alloc] initWithFrame: CGRectMake(10, 10,self.view.frame.size.width-125, 30)];
text1.backgroundColor=[UIColor whiteColor];
UITextField* text2 = [[UITextField alloc] initWithFrame: CGRectMake(10, 45, self.view.frame.size.width-125, 30)];
text2.backgroundColor=[UIColor whiteColor];
UITextField* text3 = [[UITextField alloc] initWithFrame: CGRectMake(10, 80, self.view.frame.size.width-125, 30)];
text3.backgroundColor=[UIColor whiteColor];
text1.layer.borderColor=[UIColor lightGrayColor].CGColor;
text1.layer.borderWidth=1;
text2.layer.borderColor=[UIColor lightGrayColor].CGColor;
text2.layer.borderWidth=1;
text3.layer.borderColor=[UIColor lightGrayColor].CGColor;
text3.layer.borderWidth=1;
text1.placeholder=@"Year";
text2.placeholder=@"Make";
text3.placeholder=@"Model";
[view addSubview:text1];
[view addSubview:text2];
[view addSubview:text3];
[alertView setValue:view forKey:@"accessoryView"];
view.backgroundColor = [UIColor whiteColor];
alertView.tag = 1;
[alertView show];
现在我想获取文本字段的值,单击保存按钮确实调用了以下类,但我没有得到值。
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
NSLog(@"AlertView is Active");
if (alertView.tag == 1 && buttonIndex != [alertView cancelButtonIndex]) {
NSLog(@"alert view working");
NSString *Year = [[alertView textFieldAtIndex:0] text];
NSLog(@"%@",Year);
}
}
我得到一个空值如下:
【问题讨论】:
标签: ios objective-c uialertview