我有多个文本字段。在其中一个中,我想显示一个 UIPickerView。我是这样做的:
-(void)showPicker{
[subject becomeFirstResponder];
actionSheet = [[UIActionSheet alloc] initWithTitle:nil
delegate:nil
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];
[actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
CGRect pickerFrame = CGRectMake(0, 40, 0, 0);
picker = [[UIPickerView alloc] initWithFrame:pickerFrame];
picker.showsSelectionIndicator = YES;
picker.dataSource = self;
picker.delegate = self;
[actionSheet addSubview:picker];
[picker release];
UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems: [NSArray arrayWithObject:@"Close"]];
closeButton.momentary = YES;
closeButton.frame = CGRectMake(260, 7.0f, 50.0f, 30.0f);
closeButton.segmentedControlStyle = UISegmentedControlStyleBar;
closeButton.tintColor = [UIColor blackColor];
[closeButton addTarget:self action:@selector(dismissActionSheet) forControlEvents:UIControlEventValueChanged];
[actionSheet addSubview:closeButton];
[closeButton release];
[actionSheet showInView:[[UIApplication sharedApplication] keyWindow]];
[actionSheet setBounds:CGRectMake(0, 0, 320, 485)];
}
-(void)dismissActionSheet{
[actionSheet dismissWithClickedButtonIndex:0 animated:YES];
}
当我关闭它时,工作表被关闭,但subject
textField 上的键盘出现。
现在:
我该怎么做才能不在该文本字段上显示键盘subject
?
这是我放弃键盘的地方:
- (void) resignKeyboard:(id)sender{
if ([name isFirstResponder])
[name resignFirstResponder];
else if ([email isFirstResponder])
[email resignFirstResponder];
else if ([message isFirstResponder])
[message resignFirstResponder];
else if ([subject isFirstResponder]) {
[subject resignFirstResponder];
}
}