我有三个TextFields,标签值为0,1,2。在第三个TextField中,我添加了一个名为addbutton
的按钮。我的问题是,如果我点击第三个文本字段,KeyBoard不会出现。但是按钮动作有效。如果我将Return更改为YES意味着,按钮操作也不能正常工作。
//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;
}