iOS - How to present large number of views with the same layout? - ios

Here is what I'd like to achieve:
1) present a fairly large number of screens (about a dozen) with identical layouts but different info. (Basically a set of info pages for different events - dynamically set)
2) the user should be able to use swipe to move between the pages, and the transitions should be animated
3) I'd prefer to manage all the data from a single view controller.
What would be the optimal way to achieve this? I was thinking of keeping only two views in memory, dynamically updating the content of the currently invisible view when the user swipes, and then animating from one view to the other. Should I use one of the container view controllers?
Thanks!

Sounds like you should look at using a UIPageViewController. It is a parent view controller that manages a group of child view controllers that each display a single page of content.
Each page would be an instance of the same class of content view controller that you create.
A page view controller uses a data source and a delegate much like a table view does.
There is an app in the Xcode docs called PhotoScroller that shows how to set up a page view controller using a swipe gesture to switch pages. It's got a lot more complexity than you need in the view controllers that display photos (those photos are large tiled images and the photo view controllers have a bunch of code you can ignore that manages tiled images.)

I'd probably use a UITableView that has cells large enough to take up the whole screen. That'll handle reusing the views (UITableViewCells) for you and you'll need to disable the tableview scrolling and implement paging when the user swipes.
Apply a rotation translation to the tableview's layer and then apply the inverse rotation translation to each of the cells if you want a horizontally-scrolling tableview.
Alternatively, I believe iCarousel will handle view reuse.

Related

Segmented Control and Scroll View, Keeping Views in Memory

What I'm trying to achieve is basically a Instagram profile type screen.
I'm trying to recreate the segmented control section and what's beneath.
I thought about putting a container view containing the segmented control and a scroll view that switches between 3-4 views.
I saw many ways of implementing this, with or without a scroll view (the one I'm not really a fan of is the .ishidden method).
My main concern is memory. I don't know if it's better to keep them in memory or load them from scratch and also how to do that. Can you point me in the right direction ?
The instagram app doesn't do exactly what you described-- it looks like the only the first two options within the segmented control swap out the view underneath. The last two navigate you to another view
You definitely want to load your views, assign them to strong properties, and then swap them out.
Add a Custom View in Interface Builder, that will be your container, and then connect it to an IBOutlet in your controller. You can instantiate your scroll views when the controller is instantiated, and then you can then add the scroll view as a subview to the container. Then when the segmented control is pressed, you can remove that subview, and replace it with the new subview selected.
Instagram would arguably have some of the largest views, as far as memory allocation is concerned, to swap out (several images). Yet you can tell that the scroll views are stored in memory because you can switch between them without reloading the images

Multiple UITableViews visible at once in one UIViewController

I have seen questions asked about mutliple UITableViews in one view but they all have only one table visible at a time. I am after something different please.
In my head I want four UITableViews visible in one UIScrollView inside one UIView. The four tables will be visible and populated at once. They will have a dynamic number of rows each so the scroll view will allow users to scroll off of the page to see rows that do not fit.
The tables would be two side by side and then below them the next two side by side so that you end up with a 2x2 square.
I can (sort of) wrap my head around how to code this in the controllers etc. but I cannot figure out how to organise the hierarchi. I have tried using the storeboard to layout the tables inside the view but 9 out of 10 attempts to drop controls in fail as I am obviously not fully understanding this.
Do I need to generate the UITableViews in the UIViews implementation file and add them as objects to the UIView? Or can I use the Storyboard?
Could someone please explain how the hierarchi of objects would be structured?
In my head it would be:
UIViewController
-> UiView
---> UIScrollView
------> UITableView
------> UITableView
------> UITableView
------> UITableView
But trying this in Storyboard doesn't work. I assume each UITableView will want its own UITableViewController and what I have read in other posts I would likey need to do this connecting in the UIViewController implementation file.
Any help is appreciated.
I think you might try to drag UITableViewController into your view Controller, at least I don't have that problem to add 4 table view into a scroll view.
here is how i added it
1.> Drag the scroll view control into view controller
Your view controller should look like this:
2.> Drag the table view control into the scroll view, and set the size and position of that table view
Your view controller should look like this:
3.> Then drag all the rest 3 table views onto Scroll view
But i would like to suggest a couple of things in your case
no using that much table view in the same view controller, it's a chaos in your codes to maintain all them. There are always better
options than 4 table view, maybe consider collection view. or even
separate the use flow.
If i were you, i won't use table view inside Scroll view, they are like scroll view inside scroll view, if you don't design the
interaction very very well, they become extremely hard to use.
If you still want to use four table view in the same view controller after all, you want to pay extra attentions on your table view datasource and delegate. very carefully handle all the cases.
Hope that helps you.
Tableviews are very customized scrollviews. I wouldn't put 4 of them on a scrollview, this wouldn't be very intuitive for the user as your finger would scroll the view in many ways depending on where exactly it touches the screen.
Instead, try having your 4 tableviews in a 2x2 pattern directly onto a simple UIView. This can be done inside the Storyboard.
As for filling up and using them, you have 2 ways :
A) Your UIViewController is the delegate and datasource of each of the 4 tableviews. When executing, you perform a switch on the first parameter (the tableview that called you) to determine the appropriate course of action.
B) You create 4 classes that each handle a single tableview, instanciate 4 objects inside your UIViewController and assign the UITableviews' delegate and datasource properties to these objects.
All technicality aside, 4 tableviews in a single screen is pretty crowded. Your design will definitely not fly on a iPhone, so I'm assuming iPad only. Even then, you should make sure that everything is visually appealing and the purpose of each control is clear. It's up to you, but I'd hate to see you work hard on an application only to see your efforts wasted because your visual design doesn't appeal to your users.
If the table views take up the entire region of the scroll view then they wont let any scroll events past to the scroll view that contains them, unless the scroll is horizontal.
For a simple one to one between a table view and a view controller, I would make each table view part of it's own UITableViewController (so you have four), and then make a UIViewController that adds each of the UITableViewControllers to it as a child.
This way you don't have to do any fancy logic around if statements on which tableview is asking for data, because the table view controllers only have one table view.
https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/CreatingCustomContainerViewControllers/CreatingCustomContainerViewControllers.html

iOS6 - Changing embedded subview in a view

I'm looking for some ideas what's the best way to implement the following behaviour (and a starting point in code/pseudo-code if possible):
BookViewController with ViewA - contains some UILabels (e.g. information about a book)
MainViewController with ViewB - contains some UI elements and displays ViewA in the middle (one view at a time)
The user should be able to swipe inside ViewB to view different books i.e. I will need to manage a number of ViewA views, create new ones and populate them with new data, and then replace the current instance visible in ViewB. So effectively I'll be changing views in the centre of the screen. What's the easiest and most efficient way to accomplish this functionality? Any suggestions comments are appreciated - thank you.
You just need one view controller. It should control a scroll view with paging enabled at the center and e.g. three book views, one visible and the ones left and right of it. The controller should manage the data displayed in these book views.

Scroll view - positioning UI elements in "out of screen" pages

I'm writing an iPhone app where I need to scroll between 3 views of data.
I'm trying to use the scroll view but in Interface Builder I have some difficulties in placing UILAbels, Text Fieldsand the other UI elements of the second and third pages because I should put them "out of the screen bounds" availble in IB (I'm not sure if I have well described the problem).
Is there any easy way to place the UI elements, in IB, for the 2nd and 3rd page ?
Would it be better to use another approch, like for example having three View controllers and then use them in the Scroll view ?
Thanks,
Corrado
I'm not entirely sure what is "driving" the three views. Will it always be three views?
If each page is a whole new screen then you could use the UIPageViewController.
This is a controller that manages a number of ViewControllers including swiping between the different view controllers.
Think of a horizontal UITableViewController but one that dispenses UIViewControllers instead of UITableViewCells.

iOS: Which approach to take - x number of dynamic UITableViews

I'm trying to figure out the best approach to take in my current situation.
I have an app with a navigation bar controller that at one point needs to present/show x number of table views.(x meaning that the number is decided by communicating with a server)... The table views will each represent e.g a class or a group... (this could be school classes or kindergarden classes)
Okay... So... Only one table view should be visible/in focus, but the others should be accessible from the same view...
E.g. The view is presented. A table view for class A is shown. The user can swipe to get class B
I've been considering different approaches, but I can't figure out the best approach to this...
I considered using a scroll view containing the x table views, where only one was visible at a time, and the others could be scrolled in view... But, after doing some research, it seems that Apple recommends that you shouldn't place table views in scroll views, because the scrolling can interfere with each other..
Using a tab bar... Again, my research told me that the navigation bar should be placed in the tab bar, and not the other way around... And I only want a tab bar on this view, and not earlier in the app..
Use a custom tab bar that better supports my "needs"...
Any ideas??
In my opinion the most important thing is that only one UITableView have to be visible. The best solution (ie the simplest) is a first UITableView with its UITableviewController that lists all the classes/categories A,B,.. retrieved from the server, and a secondary UITableView (ie controller /+ tableView) that will display the detailed list for a given class of items. You may also continue to drill down your data tree other sub-tableViews.
I recommend to use a UINavigationController to push/pop your tableViews when a cell is selected.
Stacking several UITableViews in a unique container view seems too much complicated and may lead to tricky and/or unwanted states.

Resources