Tableview没有在ios中选择需要选取器视图

Tableview没有在ios中选择需要选取器视图,ios,iphone,Ios,Iphone,我想在UITableView方法-DidSelectRowatineXpath上显示选择器视图。这是一个样本设计,我需要自定义选择器显示食品名称,而不是日期和时间。节中的行数大于10。选择单元格后,将显示选择器视图,并从选择器视图中选择值。我怎样才能做到这一点 使用以下方法在TableViewController中实现UIPickerViewDataSource和UIPickerViewDelegate协议: numberOfComponentsInPickerView中的列PickerView

我想在UITableView方法-DidSelectRowatineXpath上显示选择器视图。这是一个样本设计,我需要自定义选择器显示食品名称,而不是日期和时间。节中的行数大于10。选择单元格后,将显示选择器视图,并从选择器视图中选择值。我怎样才能做到这一点


使用以下方法在TableViewController中实现UIPickerViewDataSource和UIPickerViewDelegate协议:

numberOfComponentsInPickerView中的列PickerView,对于您的情况可能是1。 pickerView:NumberOfRowsIn要显示的行的组成部分,可能是您的数据数组计数。 pickerView:rowHeightForComponent:components中每一行的高度,我认为在未实现的情况下会有一个默认值,但您可能还是想更改它。 pickerView:titleForRow:forComponent:title,如果您只想显示每个组件的文本,这与TableView中的CellForRowatineXpath方法非常相似。 如果您希望以更个性化的方式呈现数据,而不是titleForRow,请执行以下操作:

pickerView:viewForRow:forComponent:reusingView: 对于用户在选择器工具中选择行时的事件处理:

pickerView:didSelectRow:Incomonent: Remmember在创建时将UIPickerView的委托设置为“self”,这将位于TableView的单元格内,因此您可以使用许多选项来创建它,在故事板中创建一个包含UIPickerView的原型单元,或者在“CellForRowatineXpath”中手动创建一个原型单元,并遵守TableViewController头文件中的协议

要实现从TableView中的常规TableViewCell到具有交互式UIPickerView的单元格的切换,您可能需要在TableViewController中使用didSelectRowAtIndexPath来刷新该单元格,您可以使用[self.TableView reloadData]或使用以下工具进行动画切换:

重新加载RowsatindExpaths:WithRowsAnimation: 例如,可以将名为“editingPickerView”的BOOL变量初始设置为“否”,并在“didSelectRowForIndexPath”方法中设置以下内容:

if(indexPath.row == X) {
   self.editingPickerView = !self.editingPickerView;
   [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation: UITableViewRowAnimationFade]; 
}
我使用故事板,所以我会有一个原型单元,用于显示正常数据,不显示UIPickerView,选中时显示不同的原型单元。 同时,在“cellForRowAtIndexPath”中,根据“editingPickerView”变量的不同,您需要采用不同的方式来提供相同的行,有点像这样:

if(editingPickerView) {
   //reuse the cell with the identifier 'UIPickerView_cell'
   UIPickerView *picker = (UIPickerView*) [cell viewWithTag:69];
   picker.delegate = self;
} else {
   //reuse the normal cell with the identifier 'normal_cell' and show data
}
self.editingPickerView = !self.editingPickerView;
//you should probably know 'a priori' what index path your picker would be in
[self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation: UITableViewRowAnimationFade];
如果要在用户在UIPickerView中选择pickerView:didSelectRow:Incomonent内的行时更改为普通单元格,则应执行以下操作:

if(editingPickerView) {
   //reuse the cell with the identifier 'UIPickerView_cell'
   UIPickerView *picker = (UIPickerView*) [cell viewWithTag:69];
   picker.delegate = self;
} else {
   //reuse the normal cell with the identifier 'normal_cell' and show data
}
self.editingPickerView = !self.editingPickerView;
//you should probably know 'a priori' what index path your picker would be in
[self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation: UITableViewRowAnimationFade];

在视图中添加隐藏的文本字段。然后在viewDidload中:

self.dtmPicker = [[UIDatePicker alloc] init];
self.dtmPicker.datePickerMode = UIDatePickerModeDate;
[self.dtmPicker addTarget:self action:@selector(DateChanged:) forControlEvents:UIControlEventValueChanged];
self.lblDate.inputView = self.dtmPicker;

我在用这个。这很简单:

这可能会有所帮助。只需用UIPicker控件替换UIDatePicker,并添加适当的委托方法。网址:

我想这就是你想要的。只需删除UIColor+Custom.h、UIColor+Custom.m及其引用就可以避免错误


URL:

但我需要在TableView中显示您可以在cell.Ya中添加文本字段..我得到了这个项目。在那个项目中,我需要VCPeopleViewController进行设计。但是检查这些会给我的设计带来麻烦。怎么做?对不起,我没听清楚。你能详细说明你在说的是哪种设计吗?。所以我可以试试。我想做第一屏。Did选择tableview并在picker中选择日期。刚刚更新了答案以显示如何从普通单元格传输到picker单元格,请记住在原型单元格内的UIPickerView上放置一个标记,以便您可以像示例一样访问。在Xcode CMD+Shift+0内的API文档中,您可以很容易地找到关于我建议的每个方法的详细解释,其中包含示例代码。您可以使用该库: