简体   繁体   English

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

[英]Converting Apple DateCell example to use UIPickerView instead of UIDatePickerView

I am in the process of converting the Apple DateCell app to use UIPickerView instead of UIDatePicker. 我正在将Apple DateCell应用程序转换为使用UIPickerView而不是UIDatePicker。 I've pulled out and replaced references to UIDatePicker with UIPickerView in storyboard and throughout the code. 我已经退出并用故事板和整个代码中的UIPickerView替换了对UIDatePicker的引用。 Still have some clean up to do on the references to DatePicker but, I am at a point where i need to convert the reference to the "dateAction" method from the "ValueChanged" event of the UIDatePicker and there is no "Send Events" what so ever for UIPickerView. 对DatePicker的引用仍有一些清理但是,我需要将引用转换为来自UIDatePicker的“ValueChanged”事件的“dateAction”方法,并且没有“发送事件”的内容所以UIPickerView。 Does anyone have any suggestions on how I can add or simulate this "ValueChanged" event to my UIPickerView? 有没有人对我如何向我的UIPickerView添加或模拟这个“ValueChanged”事件有任何建议? Also, any advice on converting the rest of the program to use UIPickerView would be greatly appreciated. 此外,任何关于将其余程序转换为使用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 works with a delegate , not a ValueChanged handler. UIPicker使用委托 ,而不是ValueChanged处理程序。 Make the controller the delegate of your picker and implement 使控制器成为您的选择器和实施的代表

– pickerView:didSelectRow:inComponent:

Don't forget to add <UIPickerViewDelegate> in the controller class declaration. 不要忘记在控制器类声明中添加<UIPickerViewDelegate>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM