转换Apple DateCell示例以使用UIPickerView而不是UIDatePickerView

我正在将Apple DateCell应用程序转换为使用UIPickerView而不是UIDatePicker。 我已经退出并在故事板和整个代码中用UIPickerView替换了对UIDatePicker的引用。 仍然对DatePicker的引用做了一些清理,但是,我需要将引用转换为来自UIDatePicker的“ValueChanged”事件的“dateAction”方法,并且没有“发送事件”是什么所以UIPickerView。 有没有人对如何在我的UIPickerView中添加或模拟这个“ValueChanged”事件有任何建议? 此外,任何关于将其余程序转换为使用UIPickerView的建议都将非常感激。

- (IBAction)dateAction:(id)sender { NSIndexPath *targetedCellIndexPath = nil; if ([self hasInlineDatePicker]) { // inline date picker: update the cell's date "above" the date picker cell // targetedCellIndexPath = [NSIndexPath indexPathForRow:self.datePickerIndexPath.row - 1 inSection:0]; } else { // external date picker: update the current "selected" cell's date targetedCellIndexPath = [self.tableView indexPathForSelectedRow]; } UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:targetedCellIndexPath]; UIPickerView *targetedDatePicker = sender; // update our data model NSMutableDictionary *itemData = self.dataArray[targetedCellIndexPath.row]; [itemData setValue:targetedDatePicker.date forKey:kDateKey]; // update the cell's date string cell.detailTextLabel.text = [self.dateFormatter stringFromDate:targetedDatePicker.date]; 

}

UIPicker使用委托 ,而不是ValueChanged处理程序。 使控制器成为您的选择器和实现的代表

 – pickerView:didSelectRow:inComponent: 

不要忘记在控制器类声明中添加