问题
I’m trying to develop an app that uses 3 different view controllers on the first tab. I have 3 options: 1 - embed the view controllers in an uipageviewcontroller 2 - embed the view controllers in a uiscrollview 3 - use containers controlled by a uisegmentedcontroller - with hidden property true or false… Each of these viewcontrollers are using collectionviews to present photos downloaded asynch from a remote server. Using 3, the photos from all view controllers, loads at the same time, so, this isn’t a good solution I think. Which one is the best solution to choose in this scenario?
回答1:
If you're worried about downloading large images simultaneously then only begin the download process in viewDidAppear
. Unless the user opens one of your view controllers the download process will not kick in.
If you're worried about multiple view controllers sitting in memory then you should design them well. Using a UITableViewController
or a UICollectionView
will help you keep your memory usage low by reusing views.
In my opinion you should pick a solution according to your UI design and simply build your code efficiently so you won't have to worry about large downloads or running out of memory
回答2:
You didn't mention a tab bar controller, which is another viable option. (Or maybe that's what you meant instead of UISegmentedControl?)
Which is best depends on the UX you want for your app more than anything.
I would put the segmented control at the bottom of the list. It's a non-standard UI, and will also require a lot of custom work from you.
来源:https://stackoverflow.com/questions/30179588/ios-different-viewcontrollers-how-to-load-them