DTInlineDatePicker 0.3.0

DTInlineDatePicker 0.3.0

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布最后发布2020年8月

Denys Telezhkin 维护。



 
依赖
DTTableViewManager~> 3.0
DTPickerPresenter~> 0.1
 

CocoaPod 平台   CocoaPod 版本   许可证 MIT

DTInlineDatePicker

这是一个 DTTableViewManagerDTPickerPresenter 的项目扩展。

从 iOS 7 开始,Apple 鼓励开发者将 UIDatePickers 以内联方式展示在 UITableView 中。不使用任何封装,这可能会编写相当多的代码。实际上,Apple 自己的示例 大约是 450 行代码。DTInlineDatePicker 提供了一种更简单的方式来实现这一点。

现在,展示 UIDatePicker 可能只需要三行代码

NSIndexPath * indexPath = [NSIndexPath indexPathForRow:1 inSection:0];
DTDatePickerPresenter * presenter = [DTDatePickerPresenter presenterWithChangeBlock:^(NSDate * selectedDate)
{
   // Update your model with NSDate     
}];
    
[self attachInlinePickerPresenter:presenter toIndexPath:indexPath];

如何

为了使用 DTInlineDatePicker 类,您的表格视图控制器需要从 DTInlinePickerTableController 继承。并且您需要使用 DTTableViewManager API 来呈现您的数据模型。您可以试一试,它非常好用 =)

响应单元格选择

有时您可能希望对具有日期选择器的单元格被选中时进行响应。例如,给选中的单元格添加颜色。DTInlineDatePicker 提供了两种方法来实现这一点

- (void)didShowPickerForIndexPath:(NSIndexPath *)indexPath;
- (void)didHidePickerForIndexPath:(NSIndexPath *)indexPath;

示例项目

为了安装 Example 项目的依赖项,您需要使用 CocoaPods。克隆项目并运行

pod install

在项目目录中。

要求

  • iOS 7
  • ARC

安装

使用 Cocoapods 安装,

pod 'DTInlineDatePicker', '~> 0.1'