繁体   English   中英

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

[英]Converting Apple DateCell example to use UIPickerView instead of 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:

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

暂无
暂无

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

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