我的搜索视图中有两个UIPickerView
和一个UITextField
。当我UIPickerView
先输入/选择这两个然后输入UITextField
.
但是当我像 InputtingUITextField
然后selection 这样更改顺序时,发生的问题是当我点击sUIPickerView
时键盘没有退出。UIPickerView
下面是我的代码
- (void) textFieldDidBeginEditing: (UITextField *) textField
//---------------------------------------------------------------
{
if (textField == self.txtFieldPoetName) {
NSLog(@"sdsdfsd");
[textField resignFirstResponder];
if ( [self.poetNameArray count] > 0 ){
[self showPoetNamePicker];
}
}
else if (textField == self.txtFieldPoemType) {
NSLog(@"jdjdjdjd");
[textField resignFirstResponder];
if( [self.poemTypeArray count] > 0 ){
[self showPoemTypePicker];
}
}
}
- (void) textFieldDidEndEditing:(UITextField *)textField{
[textField resignFirstResponder];
}
- (void)showPoetNamePicker {
[self resignKeyboard];
startXMLParser_ = NO;
self.actionSheet = [[[UIActionSheet alloc] initWithTitle:nil delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil]autorelease];
self.actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
self.actionSheet.title = @"Poet Name";
self.poetNamePicker = [[[UIPickerView alloc] init]autorelease];
self.poetNamePicker.showsSelectionIndicator = YES;
self.poetNamePicker.dataSource = self;
self.poetNamePicker.delegate = self;
PickerType = 1;
//Set up the display frame
self.poetNamePicker.frame = CGRectMake(0, 35, 320, 120);
//Add the picker to the view
[self.actionSheet addSubview:self.poetNamePicker];
UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"Done"]];
closeButton.momentary = YES;
closeButton.frame = CGRectMake(260, 6.0f, 50.0f, 27.0f);
closeButton.segmentedControlStyle = UISegmentedControlStyleBar;
closeButton.tintColor = [UIColor blackColor];
[closeButton addTarget:self action:@selector(hidePicker:) forControlEvents:UIControlEventValueChanged];
[self.actionSheet addSubview:closeButton];
[closeButton release];
[self.actionSheet showInView:self.appDelegate.tabBarController.view];
[self.actionSheet setBounds:CGRectMake(0, 0, 320, 385)];
}
- (void)showPoemTypePicker {
[self resignKeyboard];
startXMLParser_ = YES;
self.actionSheet = [[[UIActionSheet alloc] initWithTitle:nil delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil]autorelease];
self.actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
self.actionSheet.title = @"Poem Type";
self.poemTypePicker = [[[UIPickerView alloc] init]autorelease];
self.poemTypePicker.showsSelectionIndicator = YES;
self.poemTypePicker.dataSource = self;
self.poemTypePicker.delegate = self;
PickerType = 2;
//Set up the display frame
self.poemTypePicker.frame = CGRectMake(0, 35, 320, 120);
//Add the picker to the view
[self.actionSheet addSubview:self.poemTypePicker];
UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"Done"]];
closeButton.momentary = YES;
closeButton.frame = CGRectMake(260, 6.0f, 50.0f, 27.0f);
closeButton.segmentedControlStyle = UISegmentedControlStyleBar;
closeButton.tintColor = [UIColor blackColor];
[closeButton addTarget:self action:@selector(hidePicker:) forControlEvents:UIControlEventValueChanged];
[self.actionSheet addSubview:closeButton];
[closeButton release];
[self.actionSheet showInView:self.appDelegate.tabBarController.view];
[self.actionSheet setBounds:CGRectMake(0, 0, 320, 385)];
}
- (void)hidePicker:(id)sender
{
if( PickerType == 1 )
{
if ( [self.poetNameArray count] > 0 &&
[self.txtFieldPoetName.text length] == 0 )
{
//self.poemTypeId = @"";
self.txtFieldPoetName.text = [self.poetNameArray objectAtIndex:0];
self.poetTypeId = [self.poetTypeIdArray objectAtIndex:0];
}
}
else if( PickerType == 2 )
{
if ( [self.poemTypeArray count] > 0 &&
[self.txtFieldPoemType.text length] == 0)
{
//self.poetTypeId = @"";
self.txtFieldPoemType.text = [self.poemTypeArray objectAtIndex:0];
self.poemTypeId = [self.poemTypeIdArray objectAtIndex:0];
}
}
[self resignFirstResponder];
self.actionSheet.hidden = YES;
[self.actionSheet dismissWithClickedButtonIndex:1 animated:YES];
if (startXMLParser_)
{
[self performSelector:@selector(startXMLParsing) withObject:nil afterDelay:0.5];
}
}
-(void)resignKeyboard{
[self.txtFieldPoetName resignFirstResponder];
[self.txtFieldPoemName resignFirstResponder];
[self.txtFieldPoemType resignFirstResponder];
}