This is an iOS control for selecting something using UIPickerView in an UIAlertController like manner

Overview

RMPickerViewController Build Status Pod Version Carthage compatible

This framework allows you to pick something with a picker presented as an action sheet. In addition, it allows you to add actions arround the presented picker which behave like a button and can be tapped by the user. The result looks very much like an UIActionSheet or UIAlertController with a UIPickerView and some UIActions attached.

Besides being a fully-usable project, RMPickerViewController also is an example for an use case of RMActionController. You can use it to learn how to present a picker other than UIPickerView.

Screenshots

Portrait

White Black Sheet White  Sheet Black
White Version Black version Sheet Black Sheet

Demo Project

If you want to run the demo project do not forget to initialize submodules.

Installation (CocoaPods)

platform :ios, '8.0'
pod "RMPickerViewController", "~> 2.3.1"

Usage

For a detailed description on how to use RMPickerViewController take a look at the Wiki Pages. The following four steps are a very short intro:

  • Import RMPickerViewController:
#import <RMPickerViewController/RMPickerViewController.h>
  • Create select and cancel actions:
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");
}];
  • Create and instance of RMPickerViewController and present it:
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];
  • The following code block shows you a complete method:
- (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];
}

Migration

See Migration on how to migrate to the latest version of RMPickerViewController.

Documentation

There is an additional documentation available provided by the CocoaPods team. Take a look at cocoadocs.org.

Requirements

Compile Time Runtime
Xcode 7 iOS 8
iOS 9 SDK
ARC

Note: ARC can be turned on and off on a per file basis.

Version 1.4.0 and above of RMPickerViewController use custom transitions for presenting the picker view controller. Custom transitions are a new feature introduced by Apple in iOS 7. Unfortunately, custom transitions are totally broken in landscape mode on iOS 7. This issue has been fixed with iOS 8. So if your application supports landscape mode (even on iPad), version 1.4.0 and above of this control require iOS 8. Otherwise, iOS 7 should be fine. In particular, iOS 7 is fine for version 1.3.3 and below.

Further Info

If you want to show an UIDatePicker instead of an UIPickerView, you may take a look at my other control called RMDateSelectionViewController.

If you want to show any other control you may want to take a look at RMActionController.

Credits

Code contributions:

  • Denis Andrasec
    • Bugfixes
  • steveoleary
    • Bugfixes

I want to thank everyone who has contributed code and/or time to this project!

License (MIT License)

Copyright (c) 2013-2017 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.
Comments
  • Several errors (XCode 6.1 - Swift)

    Several errors (XCode 6.1 - Swift)

    Hello and thank you for RMPickerViewController and for RMDateSelectionViewController!

    I am using RMDateSelectionViewController without any issues on my test project.

    Although, when I add RMPickerViewController, I import the .h file on my bridging header I am getting the following errors:

    http://i.imgur.com/69d2LIY.png

    Any idea on how to resolve?

    opened by ispiropoulos 13
  • Picker options show in simulator, but not on a device

    Picker options show in simulator, but not on a device

    I'm making an app in Swift, and when invoking my instance of RMPickerViewController in the simulator, all goes well, but when I run it on my iPhone 5s on iOS 8.1.1 (built with the iOS 8.2 SDK), none of the options in the picker show, and I'm left with a blank square

    bug Waiting for Apple 
    opened by raysarebest 13
  • Doesnt show up when inside a UINavigationController

    Doesnt show up when inside a UINavigationController

    For some reason, which i dont know, when i present the PickerViewController doesnt show up if im inside a UINavigationController.

    @IBAction func showValues(sender: AnyObject) {
        let selectAction = RMAction(title: "Select", style: RMActionStyle.Done) { (controller) -> Void in
            let picker = (controller as! RMPickerViewController).picker
            var row = picker.selectedRowInComponent(0)
            println(row)
        }
        let cancelAction = RMAction(title: "Cancel", style: RMActionStyle.Cancel) { (controller) -> Void in
    
        }
        let pickerController = RMPickerViewController(style: RMActionControllerStyle.White, selectAction: selectAction, andCancelAction: cancelAction)
    
        pickerController.picker.delegate = self
        pickerController.picker.dataSource = self
        presentViewController(pickerController, animated: true, completion: nil)
    

    // The previous code doesnt show the picker if im inside a Nav, but the date works // I'm uneable to reproduce the issue on other project since its probably a bug with the library i'm using for a menu //This works and show up // let dateSelectionController = RMDateSelectionViewController(style: RMActionControllerStyle.White, selectAction: selectAction, andCancelAction: cancelAction) // dateSelectionController.datePicker.datePickerMode = UIDatePickerMode.Date // self.presentViewController(dateSelectionController, animated: false, completion: nil) }

    https://github.com/dekatotoro/SlideMenuControllerSwift

    func changeMainViewController(mainViewController: UIViewController,  close: Bool) {
    
        self.removeViewController(self.mainViewController)
        self.mainViewController = mainViewController
        self.setUpViewController(self.mainContainerView, targetViewController: self.mainViewController)
        if (close) {
            self.closeLeft()
            self.closeRight()
        }
    }
    

    This is the function where it changes the vc, if here i send a Nav i cant show up the datepicker (its not shown and when i retry it says: <RMPickerViewController: 0x7fe1c05ae690> on <ApperStreet.AddressVC: 0x7fe1c059a130> which is already presenting (null) Any hints?

    opened by ivangodfather 9
  • Call didSelectRows/didCancel after picker dismissed

    Call didSelectRows/didCancel after picker dismissed

    I have a trivial situation when I need to push new controller in navigation stack when user taps "Select" in Picker VC. I am surprised, but it seems that UIKit tries to push new controller in context of picker, in that case the next controller does not have a navigation bar and seems like being pushed outside of navigation stack:

    - (void)pickerViewController:(RMPickerViewController *)vc didSelectRows:(NSArray *)selectedRows {
        [self performSegueWithIdentifier:kGoalsControllerSegueID sender:self];
    }
    

    A workaround to this problem right now is 0.5s delay before performing segue. I will see if I can help with PR here, but probably tomorrow.

    Idea: add completion handler to dismiss method and use it to call delegate methods when dismissed. It would be easy to do without breaking current logic.

    bug 
    opened by pronebird 9
  • ios 7 bug

    ios 7 bug

    First we need to edit this line

    if(UIAccessibilityIsReduceMotionEnabled()) { ... }
    

    to

    if(UIAccessibilityIsReduceMotionEnabled != NULL) { ... }
    

    for avoiding crash on iOS 7.x but after show the picker on iOS 7 the whole view be white background see image please .. http://oi58.tinypic.com/20ruvex.jpg

    Could you please tell me what is going wrong ?

    opened by mrhaxic 7
  • Customisation of buttons

    Customisation of buttons

    Hello,

    it would be nice to have customisation options on the Cancel and Select buttons. Currently the buttons seems to be fairly hardcoded in setupUIElements (colors, font etc).

    I will probably modify the code to support this and can open a PR if it's of interest to wider audience?

    enhancement 
    opened by mkoppanen 5
  • Display issue in landscape orientation on iPhone 6 / 6+

    Display issue in landscape orientation on iPhone 6 / 6+

    When showing the picker in landscape orientation on iPhone 6/6+ the picker view is not displayed in it's entirety. The issue is not present when first displaying the picker in portrait orientation and then rotating. It is also not present on iPhone 5s/4s or iPad.

    opened by steveoleary 5
  • Get the text of selected rows

    Get the text of selected rows

    Hi,

    How chould I get the text/NSString of selected rows ?

    • (void)pickerViewController:(RMPickerViewController *)vc didSelectRows:(NSArray *)selectedRows

    Thanks

    opened by haxinc 5
  • I'm unable to use the library with swift

    I'm unable to use the library with swift

    Hi, i added a little project where i can't set the delegate of the RMPickerVC, can you have a look at it? Thx

    http://ruiznadal.com/TestRMPicker.zip

    Im making another example for the datepicker also

    opened by ivangodfather 4
  • Warning Issue: UIVisualEffectView and opacity animation

    Warning Issue: UIVisualEffectView and opacity animation

    I am trying to fix the following warning under IOS 8.4 and xCode 6:

    <UIVisualEffectView is being asked to animate its opacity. This will cause the effect to appear broken until opacity returns to 1.
    

    There is a discussion of this issue of SO here http://stackoverflow.com/questions/26325141/what-does-the-runtime-warning-this-will-cause-the-effect-to-appear-broken-until

    Any help would be appreciated and thanx in advance.

    opened by wm-j-ray 4
  • Add `Cartfile`

    Add `Cartfile`

    Right now if one wants to use just RMPickerViewController via Carthage, the RMActionController dependency is not resolved automatically so it needs to be added to Cartfile manually.

    This PR adds missing Cartfile so it can be resolved automatically. It is alternative to already existing https://github.com/CooperRS/RMDateSelectionViewController/pull/85

    opened by olejnjak 3
  • Text not showing in iOS 13

    Text not showing in iOS 13

    Using iOS 13.1 beta 2 Xcode 10.3 iPhone XS RMPickerViewController 2.3.1

    In iOS 13 when I display a RMPickerViewController no text shows up. When I swipe up or down I still feel the haptic feedback so I believe it's just the color of the text. I have tried it using both dark mode and normal light mode with no luck.

    Edit: When Dark Mode is turned on the labels can be seen but when Dark Mode is turned off the labels can't be seen.

    IMG_1300

    opened by jaymathew 1
  • Tapping the

    Tapping the "OK" button too fast while `UIPickerView` is still "animating/rotating" results in the wrong/previous selection. Should delay action/unload?

    I've run into this while working a bit too quickly between views before.

    If you flick the UIPickerView to a selection, and then it nearly finishes rotating but hasn't 100% finished when you hit "OK", the previous value will still be considered active because the new delegate method hasn't fired before the other callbacks and stuff go through for "OK".

    This is a problem with UIPickerView (not this module) in general to be honest... but requires a workaround. It's clear that a selection has been made by the user because it's already settled on a given choice and isn't accelerating fast enough to move past it, but it doesn't account for the fact that there's no reason the user would want the previous selection at that point instead without pressing "Cancel".

    Is it possible to get a fix or workaround for this?

    bug Waiting for Apple 
    opened by benguild 2
Releases(2.3.1)
Owner
Roland Moers
Roland Moers
This is an iOS control for presenting any UIView in an UIAlertController like manner

RMActionController This framework allows you to present just any view as an action sheet. In addition, it allows you to add actions around the present

Roland Moers 542 Dec 5, 2022
Use UIAlertController like a boss.

Description Requirements Installation CocoaPods Carthage Usage License Description CatAlertController is a high level manager object that with chainin

Kcat 8 Feb 8, 2022
A simple, customizable popup dialog for iOS written in Swift. Replaces UIAlertController alert style.

Introduction Popup Dialog is a simple, customizable popup dialog written in Swift. Features Easy to use API with hardly any boilerplate code Convenien

Orderella Ltd. 3.8k Dec 20, 2022
A customizable, full-feature, lightweight iOS framework to be used instead of UIAlertController.

A customizable, full-feature, lightweight iOS framework to be used instead of UIAlertController.

Ali Samaiee 11 Jun 6, 2022
A simple custom popup dialog view for iOS written in Swift. Replaces UIAlertController alert style.

A simple custom popup dialog view for iOS written in Swift. Replaces UIAlertController alert style.

donggyu 5 Jan 26, 2022
Swifty, modern UIAlertController wrapper.

Alertift Alertift.alert(title: "Alertift", message: "Alertift is swifty, modern, and awesome UIAlertController wrapper.") .action(.default("❤️"))

Suguru Kishimoto 287 Jan 7, 2023
Advanced usage of UIAlertController and pickers based on it: Telegram, Contacts, Location, PhotoLibrary, Country, Phone Code, Currency, Date...

Alerts & Pickers Advanced usage of native UIAlertController with TextField, TextView, DatePicker, PickerView, TableView, CollectionView and MapView. F

RV 5.5k Dec 22, 2022
An easier constructor for UIAlertController. Present an alert from anywhere.

ALRT An easier constructor for UIAlertController. Present an alert from anywhere like this. ALRT.create(.alert, title: "Alert?").addOK().addCancel().s

Masahiro Watanabe 97 Nov 11, 2022
Easy Swift UIAlertController

EZAlertController Easy Swift UIAlertController One line setup for all UIAlertControllers Button action with closures instead of selectors Easily custo

Kan Yilmaz 366 Sep 14, 2022
Simple UIAlertController builder class in Swift.

Kamagari Simple UIAlertController builder class in Swift. Features AlertBuilder class to simply build UIAlertController by using method chaining UIAle

Kazunobu Tasaka 78 Nov 29, 2022
PMAlertController is a great and customizable alert that can substitute UIAlertController

PMAlertController is a small library that allows you to substitute Apple's uncustomizable UIAlertController, with a beautiful and totally customizable

Paolo Musolino 2.5k Jan 3, 2023
PMAlertController is a great and customizable alert that can substitute UIAlertController

PMAlertController is a small library that allows you to substitute Apple's uncustomizable UIAlertController, with a beautiful and totally customizable

Paolo Musolino 2.5k Jan 3, 2023
Advanced usage of UIAlertController and pickers based on it: Telegram, Contacts, Location, PhotoLibrary, Country, Phone Code, Currency, Date...

Alerts & Pickers Advanced usage of native UIAlertController with TextField, TextView, DatePicker, PickerView, TableView, CollectionView and MapView. F

RV 5.5k Dec 26, 2022
Simple Alert View written in Swift, which can be used as a UIAlertController. (AlertController/AlertView/ActionSheet)

DOAlertController Simple Alert View written in Swift, which can be used as a UIAlertController replacement. It supports from iOS7! It is simple and ea

Daiki Okumura 406 Sep 5, 2022
An easy to use UIAlertController builder for swift

LKAlertController An easy to use UIAlertController builder for swift Features Short and simple syntax for creating both Alerts and ActionSheets from U

Lightning Kite 97 Feb 8, 2022
Customizable replacement for UIAlertController

ActionSheet Customizable replacement for UIAlertController. Requirements Installation Swift Package Manager The Swift Package Manager is a tool for au

Horizontal Systems 0 Oct 6, 2022
UIAlertController with continuity.

CuckooAlert Allow multiple use of presentViewController to UIAlertController. You may be disappointed from this. Do you imagine that cuckoo spit out s

Jay Choi 5 Feb 2, 2020
UIPicker inside a UIAlertController

DPPickerManager UIPicker inside a UIAlertController HOW TO USE : // Strings Picker let values = ["Value 1", "Value 2", "Value 3", "Value 4"] DPPickerM

Prioregroup.com 45 May 30, 2022
An easier constructor for UIAlertController. Present an alert from anywhere.

ALRT An easier constructor for UIAlertController. Present an alert from anywhere like this. ALRT.create(.alert, title: "Alert?").addOK().addCancel().s

Masahiro Watanabe 97 Nov 11, 2022