Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two questions: Only one child view controller & asynchronous menu fetching #399

Open
ivanmih opened this issue Jun 12, 2017 · 5 comments
Open

Comments

@ivanmih
Copy link

ivanmih commented Jun 12, 2017

Probably this library isn't built for these specific purposes, but it might be good to cover these edge cases anyway.
I am asking these questions here and not on stack overflow because they are causing crashes in my app.

First of all, in my situation, number of child view controllers with their names and relevant data comes from the server. Since 'viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController]' method needs to return viewcontrollers as soon parent view loads, i've blocked the main thread until networking returns data from the server.
Is it possible to somehow populate child view controllers after async networking call have retrieved data?
I've been trying to make a workaround and return a dummy view controller and reloadPagerTabStripView after networking. This causes my app to go into some kind of a deadlock, blocking the app and creating some kind of memory and processor usage outrage. Processor is going to 200% and memory rockets by gigabytes (simulator).
Current workaround consists of returning two dummy view controllers, solution which i quite dislike.

Thanks!

@ivanmih
Copy link
Author

ivanmih commented Jun 13, 2017

Update:
As for the second question, it seems that one dummy view controller works on the phone, but not on the simulator.
And if i add two dummy view controllers the first one is simply white although i change it's color and add some components.

@santiagofm
Copy link
Contributor

Hey @ivanmih ! Where you able to find a workaround for this issue ?
Cheers

@ivanmih
Copy link
Author

ivanmih commented Jun 28, 2017

Hey @santiagofm.
I couldn't think of any smarter solution than having two dummy view controllers which are being replaced by what i get from the server after async request.
override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] { var children = [UIViewController]() if menuItems.count == 0 { let child = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "DummyVC") as! DummyVC children.append(child) children.append(child) return children } else { let menuItemsNames = menuItems.map{$0.name} for menuItem in menuItems { let child = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "MainVC") as! MainVC child.url = menuItem.url children.append(child) } return children } }

It's something like this.

Also, interesting thing is that the first dummy child viewcontroller is completely white although i've changed it's color.

@ivanmih
Copy link
Author

ivanmih commented Jul 26, 2017

Just stumbled upon another problem of a previous approach.
Second call of a viewControllers method never actually updates viewcontrollers count.
So, for the first call it returns two dummy view controllers, and when i call this method again, after networking call, using reloadPagerTabStripView(), it does what needs to be done at first glance. It gives me complete list for buttonbarmenu and also gives me exactly the same number of view controllers for swiping horizontally. But if i need to use moveToViewController method it breaks the app with fatal error. It seems that it haven't updated the number of view controllers which moveToViewController method uses. Strange thing.
If you have any thoughts please let me know

@dmead28
Copy link

dmead28 commented Feb 20, 2018

Any resolution on this? I think this is the source of my problem as well. Getting a crash on if !indexPathsToReload.isEmpty { buttonBarView.reloadItems(at: indexPathsToReload) }

Still haven't been able to diagnose / reliably reproduce it, but it does happen when loading them asynchronously

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants