Multiple UITableViews visible at once in one UIViewController - ios

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

Related

Multiple instances of the same UIView in UIScrollView

I've used this answer to implement a UIScrollView with paging.
It works great as a start, but what I want to be able to do is for each page in the UIScrollView, I want a separate instance of the same UIView.
For example, say I have ContentViewController, and I want to use 4 instances of it's UIView;
1 for each of the pages on the UIScrollView - how do I go about doing that?
My initial thought was to instantiateViewController(withIdentifier), and then reuse it's .view' property inside thefor` loop, but this only gave me the correct view once, and the other 3 were blank subviews.
Any help would be much appreciated.
Thanks!
You could instantiate the ViewController multiple times (in a for loop) and then fetch each controller's view and add it to the scroll view. But you have to be aware that now you also have 4 Controllers, each for one view.

IOS what is the view with image at the top and table view at the rest

I am building a small application for basketball teams.
Each team has a logo and a list of players.
I want to build a view controller for each team.
What is the best practice for that considering the logo and the table view?
What I have thought
I've thought that I should use a UITableViewControler, but I wouldn't be able to insert the image. In other words, I could insert it at the first cell but I don't thing it is the best practice.
Edit
I also thought to use a tableView with two cell identifiers.
Could you help me please?
I appreciate your time and efforts.
Regards,
UITableView has a tableHeaderView and a tableFooterView. These are displayed above and below your table respectively. They are not to be confused with section headers and footers.
https://developer.apple.com/library/ios/documentation/uikit/reference/UITableView_Class/Reference/Reference.html
Chris' answer is probably the best answer for this case because all you need is a view at the top of your table view. If you needed something more complex, you could create a regular UITableViewController, add a container view to it, and control-drag from the container view to a UITableViewController scene in your storyboard. This would creat an "embed segue", and turn the table view controller into a child view controller. that would let you do things like place more than one UITableViewController on a window, add multiple buttons/labels on the top/sides, or whatever.

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

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.

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.

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