CooperRS/RMPickerViewController

Doesnt show up when inside a UINavigationController

ivangodfather opened this issue · 9 comments

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?

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?

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

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

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

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

UIApplication.sharedApplication().keyWindow?.rootViewController?.presentViewController(pickerController, animated: true, completion: nil)

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.

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

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 :/

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