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

Doesnt show up when inside a UINavigationController #37

Closed ivangodfather closed 9 years ago

ivangodfather commented 9 years ago

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?

CooperRS commented 9 years ago

In the picker example: Which view controller do you use to present the picker view controller? presentViewController(pickerController, animated: true, completion: nil) seems to be incomplete :/

Also: The date picker view controller example presents the date picker view controller unanimated, while the picker view controller example presents animated. If you present the picker view controller unanimated, does this solve your issue?

ivangodfather commented 9 years ago

The problem is that if this VC is inside a NavigationController doesnt show the picker (but works fine with your datepicker), i will make a project example in a few

ivangodfather commented 9 years ago

Hi, i created a project to show you the problem, see if i load the VC without a previous nav im able to show the picker. http://www.ruiznadal.com/TestPickerHere.zip

CooperRS commented 9 years ago

Edit: Forget about this post. There is way too much stuff in my downloads folder :D

CooperRS commented 9 years ago

Hmm, what does work ist the following, but it's kind of a fallback:

UIApplication.sharedApplication().keyWindow?.rootViewController?.presentViewController(pickerController, animated: true, completion: nil)
CooperRS commented 9 years ago

What also works is

slideMenuController()?.presentViewController(pickerController, animated: true, completion: nil);

Most of the time, these problems can be solved by choosing the right view controller to present another view controller on.

ivangodfather commented 9 years ago

yeah, totally right, presenting from slideMenuController works. Why i can't present from any viewcontroller?

CooperRS commented 9 years ago

Why i can't present from any viewcontroller?

That's a good question. I don't know. But in the RMPickerViewController demo project the view controller that presents the picker view controller is wrapped into a UINavigationController, too. Using self for presenting the picker view controller works fine here, no need for using the UINavigationController for presentation.

I think the problem is somewhere in the SlideMenuController. In particular because using the SlideMenuController for presentation works. But I cannot say where :/

ivangodfather commented 9 years ago

Ok i'll stick presenting from SliderMenuController, thx you for the support!