Split UITableview horizontally in IOS? - ios

I have a SQLite project in IOS for Ipad. the database contains one table with a lot of products. what I want to do is separate this products into categories. so that i can make a separate tableview for each category. So my question is, can I use one table view with different sections, but put this sections side by side horizontally? The application only work on landscape mode. I hope the question is clearly enough. Thank's.

You can achieve this using a UICollection view (iOS6+ only, but there is an open source back-port here), or you can roll your own using scroll views.
The collection view scrolls horizontally, and has a number of items matching the sections in your catalogue.
Each cell of the collection view contains a header and a table view, holding the detail from the appropriate section.
Use child view controllers to keep your code clean - the view for each cell should be managed by its own view controller, which doesn't need to know it is in a collection view cell.

Related

Swift a two views within a collection view controller

I want to know how to be able to use multiple views inside a collection view controller besides only having a collection view. I have looked at different tutorials but they only show me how to have two different views in different view controllers. I want to be able to put labels above my collection view cells. But it won't let me drag a normal view onto the collection view controller so I cannotput any labels above my cells this it what happens when I try to do it. The labels get pushed to the top left corner. Any help is greatly appreciated.
You can use a UIViewController instead of a UICollectionViewController.
To do so you can follow the accepted answer here: How to make a simple collection view with Swift

iOS - Performance Issues with Embedded Table View in Storyboard

A project I'm working on has a storyboard set up as follows:
Tableview controller (A) contains a tableview of static cells
Each static cell is a container view
One of these container views embeds another table view controller (B)
The table view of controller B is tableview with dynamic prototypes.
Everything works and renders appropriately, however I have begin to run into a performance problem when the number of cells in the embedded table view controller (B) becomes very large.
What seems to be happening is that iOS is allocating / attempting to render all the cells (ie calling cellForRowAtIndexPath), even those which are offscreen. This is because the embedded table is large enough to show all cells, because scrolling is disabled for this table and instead the root controller (A) scrolls the content.
Does anyone know a way to make this situation more performant when the embedded table view has a large number of cells? I thought about creating an artifically paged system where cells are only loaded when the user scrolls, however initial cells which have scrolled out of the view would still remain allocated, so I would have to set up some sort of dynamic allocation, which is what iOS already does if you simple use a single table view.
I have seen this design pattern proposed elsewhere and it seems Apple is really pushing adoption of containers as it makes for clean and modular code using storyboards, so I am hoping that there is a simple solution to this that I am missing.
Thanks.

Adding a collection or tableview or custom view to a scrollview in ios 8

I have a UIScrollView with lots of sub views on the scrollview. I have a picture, buttons, textfields and the like that all work fine.
Now I want to add a comment section below all this that "acts" like a UITableView.
What is the best way to accomplish this? I want the comment section to load 10 comments when that part of the view appears, and continually add 10 more comments when the 6th comment appears. There should also be an activity indicator too.
I know you can't put a collection view or tableview with a scrollview (according to Apple) as their are inherited from UIScrollView. And making the whole view controller a table view or collection view is tough since I have so many subviews and actions all linked up already.
What's the best approach?
Thanks.
You can create a new table view controller and load (add subview on cell content view) your current controller as first cell of table view controller.

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

Creating a multi column tableview/collectionview IOS

I need to create a multiple columned table which has independent scrolling for each view. Each column will contain sections that can be expanded to hold line items. All columns may not contain an equal number of sections. I was wondering what will be the best way to approach this.
I would recommend have each table view be contained in their own UITableViewController. Then you can use a container controller to display each table view controller in as subviews.
See: Creating Custom Container View Controllers
The advantage of this approach is that you can create a generic container view that only needs to worry about the location and sizing of the sub-view controllers. Each sub-view controller could worry about their own content. Thus you could have sub-view controllers be table view controllers, navigation view controllers or whatever you need at the time.
It sounds as though your columns won't really have anything to do with one another.
If so, just create three tableViews, and give each their own datasource and delegate.

Resources