我有一个定制的UITableView单元
@interface PickTypeCell : UITableViewCell <UIPickerViewDataSource, UIPickerViewDelegate>
@property (weak, nonatomic) IBOutlet UITextField *txtTextField;
@property (readwrite, retain) IBOutlet UIPickerView* dtpPicker;
@end实现文件看起来像
@implementation PickTypeCell
@synthesize txtTextField;
@synthesize dtpPicker;
- (void)awakeFromNib
{
NSLog(@"inside PickTypeCell init");
//assign this to the picker delegate / datasource
dtpPicker = [[UIPickerView alloc] init];
dtpPicker.dataSource = self;
dtpPicker.delegate = self;
// assign the picker to the text field input view,so the picker is displayed when the text field receives input event
txtTextField.inputView=dtpPicker;
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
//retuns the number of columns of the picker view : 1
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
//return the number of rows for each component : the number of tree types
return 5;
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
//called to get the text to be displayed on each row of the picker
return @"HAHAH";
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
//called when the user clicks on a row of the picker view
txtTextField.text=@"HABOOOOUN";
}加载单元格时,将显示输入文本字段。单击“文本”字段时,将按预期显示包含"HAHAH“的5行选择器视图。单击一行时,文本字段中的文本将被更新为"HABOOOOUN“字符串。
但挑选者仍在显示,我不知道该如何排除它。
当用户单击选择器中的任何一行时,我希望选择器被取消。如果用户再次单击文本字段,则将再次显示选择器。
我尝试在“dtpPicker”方法中使用resignFirstResponder,但没有成功。为什么?
发布于 2013-10-18 18:36:16
你应该试着辞职UItextField [txtTextField resignFirstResponder]
发布于 2013-10-18 18:44:42
PickTypeCell *cell = (id)[tableView cellForRowAtIndexPath:indexPath];
[cell.txtTextField resignFirstResponder];如果您点击textField或发送消息,[textField becomeFirstResponder] textField成为第一个响应器,键盘自动出现。如果您想隐藏键盘,您应该调用[textField resignFirstResponder];,您可以将键盘更改为其他视图textField.inputView = myView;,您已经完成了这些操作。
https://stackoverflow.com/questions/19456691
复制相似问题