Converting Apple DateCell example to use UIPickerView instead of UIDatePickerView

I am trying to convert an Apple DateCell application to use a UIPickerView instead of a UIDatePicker. I pulled out and replaced links to UIDatePicker using UIPickerView in the storyboard and in the whole code. There is still some possibility to link to DatePicker, but I'm at the point where I need to convert the dateAction method link from the "ValueChanged" event to UIDatePicker, and there is no "Send Events", which is why it is for UIPickerView. Does anyone have any suggestions on how I can add or simulate this "ValueChanged" event in my UIPickerView? In addition, any advice on converting the rest of the program to using UIPickerView would be very helpful.

- (IBAction)dateAction:(id)sender { NSIndexPath *targetedCellIndexPath = nil; if ([self hasInlineDatePicker]) { // inline date picker: update the cell date "above" the date picker cell // targetedCellIndexPath = [NSIndexPath indexPathForRow:self.datePickerIndexPath.row - 1 inSection:0]; } else { // external date picker: update the current "selected" cell 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 date string cell.detailTextLabel.text = [self.dateFormatter stringFromDate:targetedDatePicker.date]; 

}

+3
source share
1 answer

UIPicker works with a delegate , not a ValueChanged handler. Make the controller a delegate of your collector and run

 pickerView:didSelectRow:inComponent: 

Remember to add <UIPickerViewDelegate> to the controller class declaration.

+2
source

All Articles