转换Apple DateCell示例以使用UIPickerView而不是UIDatePickerView [英] Converting Apple DateCell example to use UIPickerView instead of UIDatePickerView

查看:85
本文介绍了转换Apple DateCell示例以使用UIPickerView而不是UIDatePickerView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am in the process of converting the Apple DateCell app to use UIPickerView instead of UIDatePicker. I've pulled out and replaced references to UIDatePicker with UIPickerView in storyboard and throughout the code. 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. Does anyone have any suggestions on how I can add or simulate this "ValueChanged" event to my UIPickerView? Also, any advice on converting the rest of the program to use UIPickerView would be greatly appreciated.

- (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 处理程序。使控制器成为选择器和实现的代表

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

– pickerView:didSelectRow:inComponent:

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

Don't forget to add <UIPickerViewDelegate> in the controller class declaration.

这篇关于转换Apple DateCell示例以使用UIPickerView而不是UIDatePickerView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆