0

当我标签到 uitextfield 时,我可以显示 uipickerview,并且可以选择一行以将选择分配给文本字段。直到这里没有问题,您可以在下面找到代码;

-(void)pickerDoneClicked
{
[il resignFirstResponder];  
mypickerToolbar.hidden=YES;
pktStatePicker.hidden=YES;
}


- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
// Show UIPickerView

return YES;
}

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 1;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:     (NSInteger)component
{
   return [arrState count];
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
return [arrState objectAtIndex:row];
}

- (void) pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
il.text = [arrState objectAtIndex:row];
NSInteger asa= [pickerView selectedRowInComponent:0];
[ilsecid setText:[NSString stringWithFormat:@"%li",(long)asa+1]];
}


- (void)viewDidLoad
{
[super viewDidLoad];
arrState= [[NSArray alloc] initWithObjects: @"class1",@"class2", @"class4",@"class10",@"class11",@"class14",@"class15",@"class16", nil];
pktStatePicker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 43, 320, 480)];
pktStatePicker.delegate = self;

pktStatePicker.dataSource = self;

[pktStatePicker  setShowsSelectionIndicator:YES];
il.inputView =  pktStatePicker  ;

mypickerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 56)];
mypickerToolbar.barStyle = UIBarStyleBlackOpaque;
[mypickerToolbar sizeToFit];
NSMutableArray *barItems = [[NSMutableArray alloc] init];
UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
[barItems addObject:flexSpace];
UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc]   
initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(pickerDoneClicked)];
[barItems addObject:doneBtn];
[mypickerToolbar setItems:barItems animated:YES];
il.inputAccessoryView = mypickerToolbar;
[self invokeService];
}

但是当我再次选择文本字段时,uipickerview 不再显示。(第一次使用后它会消失,即使我再次点击也不显示。

4

1 回答 1

0

是的bobnoble,textFieldShouldBeginEditing 需要隐藏工具栏和pickerview 否。感谢您指出我的缺失线。

于 2013-06-30T13:11:25.820 回答