gpt4 book ai didi

iphone - 点击 uipickerview 时键盘不退出

转载 作者:行者123 更新时间:2023-11-29 04:23:03 25 4
gpt4 key购买 nike

我的搜索 View 中有两个 UIPickerView 和一个 UITextField。当我首先输入/选择两个 UIPickerView 然后输入 UITextField 时,一切工作正常。

但是当我更改顺序(例如输入 UITextField)然后选择 UIPickerView 时,发生的问题是当我点击 UIPickerView 时键盘不会退出>s.

下面是我的代码

- (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];

}

最佳答案

编辑:

- (void) textFieldShouldBeginEditing: (UITextField *) textField
{
if (textField == self.txtFieldPoetName)
{
if( [self.poemNameArray count] > 0 ){
[self showPoetNamePicker];
}
return NO;
}
else if (textField == self.txtFieldPoemType)
{
if( [self.poemTypeArray count] > 0 ){
[self showPoemTypePicker];
}
return NO;
}
else
{
return YES;
}
}

在 showPoetNamePicker 中添加以下内容:

 - (void)showPoetNamePicker
{
[self.view endEditing:YES];
........
........
}

关于iphone - 点击 uipickerview 时键盘不退出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12720896/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com