qmathe / DropDownMenuKit

UIKit drop down menu, simple yet flexible and written in Swift
Other
303 stars 38 forks source link

Default selecting a row. #3

Closed Fredehagelund92 closed 8 years ago

Fredehagelund92 commented 8 years ago

Don't know whether this is related to the repository itself, however i believe that this feature would be useful.

i've tried with following code, but does not seem to work.

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    let rowToSelect = IndexPath.init(row: 0, section: 0)

    navigationBarMenu.menuView.selectRow(at: rowToSelect, animated: false, scrollPosition: .none)

    // Calling manually to the delegate method
    navigationBarMenu.tableView(navigationBarMenu.menuView, didSelectRowAt: rowToSelect)
}
qmathe commented 8 years ago

Thanks for reporting this issue. I'll take a look at it when I come back next week.

qmathe commented 8 years ago

In the app example, if I replace the existing ViewController.viewWillAppear: with the implementation below, the second menu cell is correctly marked with a checkmark after launch.

    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)

        navigationBarMenu.container = view
        toolbarMenu.container = view

        let rowToSelect = NSIndexPath(forRow: 1, inSection: 0)

        navigationBarMenu.menuView.selectRowAtIndexPath(rowToSelect, animated: false, scrollPosition: .None)
        navigationBarMenu.tableView(navigationBarMenu.menuView, didSelectRowAtIndexPath: rowToSelect)
    }

Your code seems to work fine for me. May be something else is wrong…

qmathe commented 8 years ago

I added DropDownMenu.selectMenuCell(:) with 0b53544c01f3e13dc5d9062b78e0483aa65f7ef5

I updated the app example to showcase it in ViewController.prepareNavigationBarMenu()

Let me know if that works well for you.