Skip to content

contentViewController won't scroll to specific page programmatically #108

@helloC1ndy

Description

@helloC1ndy

Hi, thank you for sharing this great project with everyone! I really like it! But I have a little issue here hoping someone could help me. Thanks a lot!!

About The Issue

I want to add my pages dynamically, reload both menu & content, and then scroll the menu & content to the last page. It turns out menuViewController works successfully, but contentViewController just can't scroll to the last page. Not sure why.

My Tries & Results

  1. reload first, scroll later
func addNewPage() {
        let vc = self.storyboard!.instantiateViewController(withIdentifier: "myViewController")
        pageList.append(vc)

        let lastPageIndex = pageList.endIndex
        
        menuViewController.reloadData()
        contentViewController.reloadData()

        menuViewController.scroll(index: lastPageIndex)
        contentViewController.scroll(to: lastPageIndex, animated: true)
    }

Result: menuViewController will scroll to the last index, but contentViewController always stays at first index.

  1. use reload-with-preferredFocusIndex function
func addNewPage() {
        let vc = self.storyboard!.instantiateViewController(withIdentifier: "myViewController")
        pageList.append(vc)

        let lastPageIndex = pageList.endIndex
        
        menuViewController.reloadData(with: lastPageIndex, completionHandler: nil)
        contentViewController.reloadData(with: lastPageIndex, completion: nil)
        
    }

Result: menuViewController will scroll to the last index, so does contentViewController. BUT, contentViewController is totally blank!! (It didn't load its input views. But when I do a little scroll, like try to scroll to previous page a little but not really scroll to there, then contentViewController will load its input view successfully.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions