0
在我的视图控制器我有5个文本字段,4成为第一响应者与键盘和一个与UIPicker,他们都被标记+1(0,1,2 ...)添加上一个和下一个按钮到我的UIPicker的辅助视图?
它恰好如此,成为Picker的第一响应者的textfield是3号,所以它卡在中间。在我的其他领域,我有我的代码设置,以便“下一步”返回按钮将我带到我的下一个字段,但是我一直无法使用选取器取得同样的结果,导致发生这种情况的代码:
-(BOOL) textFieldShouldReturn:(UITextField *) theTextField {
if (theTextField == self.textFieldE) {
[theTextField resignFirstResponder]; //This of course being the last text field
} else {
[(UITextField *)[theTextField.superview viewWithTag:theTextField.tag+1]
becomeFirstResponder];
}
return YES;
}
UIPickerView有一个附件视图附加到一个完成按钮,事实上resignFirstResponder
,但我需要能够添加prev和下一个按钮,使firstResponder -1.tag或+ 1.tag,因为选择器卡在位置编号3
这是我的选择器代码:
- (void)textFieldDidBeginEditing:(UITextField *)textField {
if (textField == self.textOutlet) {
self.textOutlet.inputView = _thePicker;
self.thePicker.hidden = NO;
UIToolbar* toolbar = [[UIToolbar alloc] init];
toolbar.barStyle = UIBarStyleBlackTranslucent;
[toolbar sizeToFit];
//to make the done button aligned to the right
UIBarButtonItem *flexibleSpaceLeft = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem* doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Done"
style:UIBarButtonItemStyleDone target:self
action:@selector(doneClicked:)];
[toolbar setItems:[NSArray arrayWithObjects:flexibleSpaceLeft, doneButton, nil]];
self.textOutlet.inputAccessoryView = toolbar;
}
}
,当然还有“完成”按钮的作用:
-(void)doneClicked:(id) sender
{
[_textOutlet resignFirstResponder]; //hides the pickerView
}
感谢提前的帮助!
好了,我给了代码尝试,但应用程序崩溃时,我选择与选择器文本字段..我换成'theTextField'与具有选择器输入文本字段的名称。我得到以下调试日志:'2013-07-12 11:34:38.979 calcApp [1519:907] - [UISegmentedControl view]:无法识别的选择器发送到实例0x1dd7bfa0 2013-07-12 11:34:38.981 calcApp [1519 :907] ***终止应用程序由于未捕获的异常'NSInvalidArgumentException',原因:' - [UISegmentedControl视图]:无法识别的选择发送到实例0x1dd7bfa0' '@Vojtech Vrbka – vzm
你有这个函数在UIViewController或你的自定义UITextField类? –