CooperRS / RMPickerViewController

This is an iOS control for selecting something using UIPickerView in an UIAlertController like manner
MIT License
381 stars 51 forks source link

I'm unable to use the library with swift #36

Closed ivangodfather closed 9 years ago

ivangodfather commented 9 years ago

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

CooperRS commented 9 years ago

Hi, you have to set the delegate and dataSource of the picker view controllers picker.

let pickerVC = RMPickerViewController(style: RMActionControllerStyle.White, selectAction: selectAction, andCancelAction: cancelAction);

pickerVC.picker.delegate = self;
pickerVC.picker.dataSource = self;

the picker view controller itself does not have a delegate or dataSource ;). Also in the demo project you have to make the ViewController implement the UIPickerViewDelegate and UIPickerViewDataSource protocol.

ivangodfather commented 9 years ago

Wow my bad, maybe i rushed too much doing the demo, but i remembered not working previous version. Now seems its working fine. Ty a lot! By the way, to get the index of the selected row/s, this is "the standart" form?

    let selectAction = RMAction(title: "Select", style: RMActionStyle.Done) { (actionController) -> Void in
        let picker = (actionController as! RMPickerViewController).picker
        let selectedRow =  picker.selectedRowInComponent(0)
    }
CooperRS commented 9 years ago

Unfortunately currently casting is neccessary. This will change with Xcode 7 and generics in Objective C. Until then we will just need to cast :/

CooperRS commented 9 years ago

I published a branch of RMActionController which contains a version of RMActionController which allows specifying the type of a RMActionControllers contentView using Generics (any class that's a subclass of UIView is possible). You can find the branch here.