PickerCells 1.1.0

PickerCells 1.1.0

测试已测试
Lang语言 Obj-CObjective C
许可证 MIT
发布最后发布2016年9月

Danis Ziganshin维护。




  • 作者:
  • Danis Ziganshin

这个类添加了 UIDatePicker 或 UIPickerView,当在您的 UITableView 中的单元格上点击时,会展开或折叠。

受 Apple 的 DateCell 示例和 andjashDateCellsController 启发。

屏幕截图

最低 iOS 版本

iOS 6.0

用法

  1. 使用 #import "PickerCells.h" 引入
  2. 实例化和设置 PickerCellsController 类。

    self.pickersController = [[PickerCellsController alloc] init];
    [self.pickersController attachToTableView:self.tableView tableViewsPriorDelegate:self withDelegate:self];
  3. 使用相应的 indexPath 添加 UIPickerViewUIDatePicker 实例

    UIPickerView *pickerView = [[UIPickerView alloc] init];
    pickerView.delegate = self;
    pickerView.dataSource = self;
    NSIndexPath *pickerIP = [NSIndexPath indexPathForRow:1 inSection:1];
    [self.pickersController addPickerView:pickerView forIndexPath:pickerIP];
    
    UIDatePicker *datePicker1 = [[UIDatePicker alloc] init];
    datePicker1.datePickerMode = UIDatePickerModeDate;
    datePicker1.date = [NSDate date];
    NSIndexPath *path1 = [NSIndexPath indexPathForRow:2 inSection:0];
    [self.pickersController addDatePicker:datePicker1 forIndexPath:path1];
  4. 看看!尝试按下指定的 indexPath 的单元格,看看选择器如何在它们下面展开。
  5. 这个类不负责为您提供选择器选中项的信息。您应该自行完成。但是,您可以通过使用相应的单元格 indexPath 从 PickerCellsController 对象中获取选择器。

    id picker = [self.pickersController pickerForOwnerCellIndexPath:indexPath];
    if ([picker isKindOfClass:UIDatePicker.class]) {
      UIDatePicker *datePicker = (UIDatePicker *)picker;
      NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
      [dateFormatter setDateFormat:@"dd-MM-yyyy"];
      cell.textLabel.text = [dateFormatter stringFromDate:[datePicker date]];
    }

安装

pod 'PickerCells'

许可证

MIT