Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/93.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 将Apple DateCell示例转换为使用UIPickerView而不是UIDatePickerView_Ios_Iphone_Objective C_Ios7 - Fatal编程技术网

Ios 将Apple DateCell示例转换为使用UIPickerView而不是UIDatePickerView

Ios 将Apple DateCell示例转换为使用UIPickerView而不是UIDatePickerView,ios,iphone,objective-c,ios7,Ios,Iphone,Objective C,Ios7,我正在将Apple DateCell应用程序转换为使用UIPickerView而不是UIDatePicker。在故事板和整个代码中,我已经将对UIDatePicker的引用取出并替换为UIPickerView。对DatePicker的引用还有一些清理工作要做,但是,我现在需要将对“dateAction”方法的引用从UIDatePicker的“ValueChanged”事件转换为“dateAction”,而UIPickerView则没有类似的“发送事件”。有人对我如何向UIPickerView添加

我正在将Apple DateCell应用程序转换为使用UIPickerView而不是UIDatePicker。在故事板和整个代码中,我已经将对UIDatePicker的引用取出并替换为UIPickerView。对DatePicker的引用还有一些清理工作要做,但是,我现在需要将对“dateAction”方法的引用从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使用的是一个,而不是一个
值已更改的处理程序。使控制器成为选择器和机具的代理

– pickerView:didSelectRow:inComponent:

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

您的建议有效。请注意:确保将UIPickerView向下拖动到视图下方的栏中,并使用该对象将代理连接到视图。如果使用表单元格中的UIPickerView对象,Xcode将抛出错误。现在我只需要找到与之等价的代码;“[itemData setValue:TargetedDataPicker.date-forKey:kDateKey];”。再次感谢你的建议。没必要。您可以有一个仅包含选择器的UITableViewCell。当单元格出列时,识别选择器(例如通过
标记
)并设置其委托。也可以在Interface Builder中设置委托。