RMPickerViewController 2.3.1

RMPickerViewController 2.3.1

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

Roland Moers 维护。




  • Roland Moers

此框架允许您在动作表单中呈现选择器来选择某些内容。此外,它允许您在呈现的选择器周围添加动作,其行为类似于按钮,可以被用户点击。结果看起来非常类似于带有 UIPickerView 和一些 UIActions 的 UIActionSheet 或 UIAlertController。

除了是一个完全可用的项目之外,RMPickerViewController 还是一个 RMActionController 用例的示例。您可以使用它来学习如何呈现实际 UIPickerView 之外的选择器。

截图

纵向

白色 黑色
White Version Black version

横向

Landscape

演示项目

如果要运行演示项目,请勿忘记初始化子模块。

使用方法

有关如何使用 RMPickerViewController 的详细介绍,请参阅 Wiki 页面。以下四个步骤是一个非常短的介绍

  • 导入 RMPickerViewController
#import <RMPickerViewController/RMPickerViewController.h>
  • 创建选择和取消动作
RMAction<UIPickerView *> *selectAction = [RMAction<UIPickerView *> actionWithTitle:@"Select" style:RMActionStyleDone andHandler:^(RMActionController<UIPickerView *> *controller) {
    NSMutableArray *selectedRows = [NSMutableArray array];
    
    for(NSInteger i=0 ; i<[controller.contentView numberOfComponents] ; i++) {
        [selectedRows addObject:@([controller.contentView selectedRowInComponent:i])];
    }
    
    NSLog(@"Successfully selected rows: %@", selectedRows);
}];

RMAction<UIPickerView *> *cancelAction = [RMAction<UIPickerView *> actionWithTitle:@"Cancel" style:RMActionStyleCancel andHandler:^(RMActionController<UIPickerView *> *controller) {
    NSLog(@"Row selection was canceled");
}];
  • 创建 RMPickerViewController 的实例并将其呈现
RMPickerViewController *pickerController = [RMPickerViewController actionControllerWithStyle:style title:@"Test" message:@"This is a test message.\nPlease choose a row and press 'Select' or 'Cancel'." selectAction:selectAction andCancelAction:cancelAction];
pickerController.picker.dataSource = self;
pickerController.picker.delegate = self;

[self presentViewController:pickerController animated:YES completion:nil];
  • 以下代码块显示了完整的方法
- (IBAction)openPickerController:(id)sender {
    RMAction<UIPickerView *> *selectAction = [RMAction<UIPickerView *> actionWithTitle:@"Select" style:RMActionStyleDone andHandler:^(RMActionController<UIPickerView *> *controller) {
        NSMutableArray *selectedRows = [NSMutableArray array];
    
        for(NSInteger i=0 ; i<[controller.contentView numberOfComponents] ; i++) {
            [selectedRows addObject:@([controller.contentView selectedRowInComponent:i])];
        }
        
        NSLog(@"Successfully selected rows: %@", selectedRows);
    }];
    
    RMAction<UIPickerView *> *cancelAction = [RMAction<UIPickerView *> actionWithTitle:@"Cancel" style:RMActionStyleCancel andHandler:^(RMActionController<UIPickerView *> *controller) {
        NSLog(@"Row selection was canceled");
    }];
    
    RMPickerViewController *pickerController = [RMPickerViewController actionControllerWithStyle:style title:@"Test" message:@"This is a test message.\nPlease choose a row and press 'Select' or 'Cancel'." selectAction:selectAction andCancelAction:cancelAction];
    pickerController.picker.dataSource = self;
    pickerController.picker.delegate = self;
    
    [self presentViewController:pickerController animated:YES completion:nil];
}

迁移

有关如何迁移到 RMPickerViewController 最新版本的说明,请参阅 迁移

文档

提供额外的文档由 CocoaPods 团队提供。请参阅 cocoadocs.org

要求

编译时间 运行时间
Xcode 7 iOS 8
iOS 9 SDK
ARC

注意:可以按文件逐个启用以翻滚的 ARC。

从版本1.4.0开始,RMPickerViewController在显示选择器视图控制器时使用自定义过渡。自定义过渡是苹果公司在iOS 7中引入的一项新功能。遗憾的是,在iOS 7的横屏模式下,自定义过渡完全损坏。这个问题已经在iOS 8中得到了修复。因此,如果您的应用程序支持横屏模式(甚至在iPad上),那么1.4.0及更高版本的此控件需要iOS 8。否则,iOS 7应该是没有问题的。特别是,iOS 7对1.3.3及以下版本仍然适用。

更多信息

如果您想显示一个UIDatePicker而不是 UIPickerView,可以看看我其他的一个控件,名为RMDateSelectionViewController

如果您想显示其他控件,可以看看RMActionController

致谢

代码贡献

  • Denis Andrasec
    • 错误修复
  • steveoleary
    • 错误修复

我想感谢所有为这个项目贡献代码和时间的人!

许可(MIT License)

Copyright (c) 2013-2016 Roland Moers

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.