为什么按钮操作在iOS的文本字段中不起作用?
我有三个标签值为0,1,2的文本字段。在第三个文本字段中,我添加了一个名为为什么按钮操作在iOS的文本字段中不起作用?,ios,objective-c,button,return,textfield,Ios,Objective C,Button,Return,Textfield,我有三个标签值为0,1,2的文本字段。在第三个文本字段中,我添加了一个名为addbutton的按钮。我的问题是,如果我单击第三个文本字段,键盘将不会出现。但按钮操作有效。如果我将返回改为“是”,则表示按钮操作也不起作用 //ThirdTextField connectionNoText=[[UITextField alloc]initWithFrame:CGRectMake(20, 30, 280, 35)]; connectionNoText.borderStyle = UITextBor
addbutton
的按钮。我的问题是,如果我单击第三个文本字段,键盘将不会出现。但按钮操作有效。如果我将返回改为“是”,则表示按钮操作也不起作用
//ThirdTextField
connectionNoText=[[UITextField alloc]initWithFrame:CGRectMake(20, 30, 280, 35)];
connectionNoText.borderStyle = UITextBorderStyleRoundedRect;
[connectionNoText setPlaceholder:@"Add directly or use me ->"];
connectionNoText.layer.borderColor = [[UIColor blackColor]CGColor];
[connectionNoText setTag:2];
connectionNoText.delegate = self;
[connectionNoView addSubview:connectionNoText];
//addButton
addButton = [UIButton buttonWithType:UIButtonTypeCustom];
[addButton addTarget:self action:@selector(addButton:) forControlEvents:UIControlEventTouchUpInside];
addButton.frame = CGRectMake(250, 10, 15, 15);
[addButton setBackgroundColor:[UIColor blueColor]];
[addButton setEnabled:YES];
[connectionNoText addSubview:addButton];
-(IBAction)addButton:(id)sender
{
if (stateText.text.length == 0)
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@""
message:@"Please select state first."
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
else
{
NSLog(@"callpop");
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
AddAreaViewController * addAreaViewController = (AddAreaViewController *)[sb instantiateViewControllerWithIdentifier:@"AddAreaViewControlleridentifier"];
[self showPopupWithTransitionStyle:STPopupTransitionStyleSlideVertical rootViewController:addAreaViewController];
}
}
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
// Show UIPickerView
if (textField.tag ==0)
{
NSLog(@"calling State");
selectionVal = 1;
[UIView animateWithDuration:0.5 delay:0.1 options:UIViewAnimationOptionCurveEaseIn animations:^{
viewForPicker.frame = CGRectMake(0, self.view.frame.size.height-260,self.view.frame.size.width, 260);
}
completion:^(BOOL finished){
}];
}
else if (textField.tag ==1 )
{
NSLog(@"calling Provider");
if ([stateText.text isEqualToString:@""])
{
[self alert];
}
else
{
selectionVal = 2;
[UIView animateWithDuration:0.5 delay:0.1 options:UIViewAnimationOptionCurveEaseIn animations:^{
viewForPicker.frame = CGRectMake(0, self.view.frame.size.height-260,self.view.frame.size.width, 260);
}
completion:^(BOOL finished){
}];
}
}
else if (textField.tag ==2)
{
NSLog(@"clicked ConnectionN0");
}
[_statePickerView reloadAllComponents];
return NO;
}
你做了什么;你会成为第一反应者吗?