Table views inside a scroll view - ios

I have this click issue on my Swift app. I'm building a profile screen with 2 UITableViews on it inside a UIScrollView. However, only 1 UITableCell is clickable (The reason why both tables have to be separated is because the top table is sorted ASC - from the latest to future dates while the bottom table is sorted DESC - from the most recent to the oldest).
The tables are auto-stretched based on the contents as shown in the code down below. The problem is only the first item is clickable.
Everything is okay in other screens with 1 UITableView. I also made sure there are no views in-front of the tables using the UI Debugger.
// Table 1
// UITableViewDelegate, UITableViewDataSource
managerUpcoming.getTable().reloadData()
// Height Constraint
heightUpcoming.constant = managerUpcoming.getTable().contentSize.height
// Resize table
managerUpcoming.getTable().frame.size.height = heightUpcoming.constant
// Update
managerPrevious.getTable().updateConstraints()
// Table 2
// UITableViewDelegate, UITableViewDataSource
managerPrevious.getTable().reloadData()
// Height Constraint
heightPrevious.constant = managerPrevious.getTable().contentSize.height
// Resize table
managerPrevious.getTable().frame.size.height = heightPrevious.constant
// Update
managerPrevious.getTable().updateConstraints()
viewContent.frame.size.height = total
scroll.contentSize.height = viewContent.frame.height
Any help and suggestions are highly appreciated. Thanks.

Having two table views inside a scrollview is a bad design IMO. Even going to the other side of the universe of Android development will suggest you not to do it. Based on the picture that you've provided on how you wanted to place the two table views, might as well have:
two separated array for the data that you've wanted to be ordered descending and one for ascending.
populate your table view in two sections. If section 0 is for ascending items then load the row / cell data within that section using your ascending data / array, then do the same for your section 1 using your descending data / array. This can easily be achieved by conditional statements inside the data source method implementation for the section and cell.
If you think you still have to implement sections on each of the already section-separated cells, then by all means you can create a custom cell to act as a section-like layout. You are not limited to create custom cells, just handle them with care.
If this simple approach isn't enough, then you can use a more advanced implementation using a collection view and that's already a different topic based on your question.
The main problem on your current design (using 2 tableviews inside a scrollview) will most probably lead you to inefficient loading of data since you need to load all the data on both of your tables just to determine the content height for the scrollview. Aside from the fact that the gestures needed additional routing, your current design will restrict the ability of your app to lazily load only the cells / data needed to be shown at the moment.

Related

Nested collection view in table view is better or multiple collection view

I have to showcase some image with a little information like title and subtitle which will be horizontally swipeable. Basically, it will be like Airbnb app which shows the category and elements in it with horizontal swipe. The only difference is that in my case number of category(row) is fixed, which is 2. DataSource is same for both rows. I have two approach first is using two CollectionView and second one is by using a TableView and nesting the CollectionView inside tableview cell. Googled and get only the implementation part for both approach not the comparison or use cases for the approach. So my question here is, which process should I follow and why?
1) Using nested Collection view will make the code complex.Generally used only when cannot be implementable using table view.
2) Table view is similar to collection view just that it can be scrollable vertical not horizontal. This make table view easy to implement.
3) In your case collection in table view will work great. Row is fixed in that case you can use static table view.

insert row in a table view without storing datasource in code

I have drawn my tableView in storyBoard with static cells and multiple sections. 6 sections each has proper number of static cells. In code, in MyTableViewController I do not implement any of the datasource or delegate methods, which logically means I do not have my model in code, the array or whatever that dataSource methods will use to populate number of sections or number of rows in a section. My question is: is it possible to insert a row to any of the sections?
I read a lot of stack questions. All of them is based on having a model array or dictionary that plays its role in dataSource methods to construct the table.
I have my table already constructed in storyBoard. I can get my number of sections with tableView.numberofSections() for example. Which means the model is stored somewhere for sure. I just need a proper method to get access to that model.
There is a reason the UITableView works the way it does with the datasource protocol. It allows iOS to use just what is needed to display on the screen at any given time as you scroll through the table, making it very efficient. Without implementing the required methods, iOS will not know how to rebuild the cell if you scroll it off the screen and then back on.
If you don't need that complexity (and really, it isn't complex and you can implement the required methods in less time than it is taking me to respond), you could use a UIStackView inside of a UIScrollView. It would allow you to simply add a set of UI components vertically down the screen, complete with scrolling.
Can you explain why you don't want to implement the UITableViewDataSource protocol?

UITableView in decoration purposes

I am trying i am working on my social network app and I need to implement my profile settings window
To show what exactly I am talking about I will attach a picture.
https://pp.vk.me/c622224/v622224461/18d2f/lqcCCkXxHiY.jpg
I have 3 following questions:
1)Which kind of cells should be used (Static, Prototype, Dynamic) in order to create this kind of view.
2)How did they manage to resize 2 of 3 cells' width in order to fit an image there too
3)Are these gaps between different sections being a different table?
1 - You must use prototype cells in order to change the data for each user
2 - The photo section can be a UIView added as subview to UITable
3 - The gaps are not because of different tables, is a table setup as Grouped instead of Plain.

It's possible to customize UICollectionView for displaying few sections like one?

I have three different kind of objects that I want to display in collection view.
But if in section 0 is only 1 element, next section starts from new column.
Can I tell to the layout that it should show items in different sections one after the other with no breaks?
Sure, but if that never changes, why not make two side-by-side sub views?
The left one contains the one element, the right one contains the collection view you originally planned to use.
That way the layout doesn't need to know how to work around the left element.
Additionally, you can use one data source. Make datasource[0] the left one,
And use datasource[indexPath.row +1] for the whole cellForRow..... method.
Just remember to set total cells in the collection view to [datasource count] -1
My solution is to use 1 section and create methods for determinate abstract sections.
In addition, I add -infoItemsCount, -visibleItemsCount and -hiddenItemsCount and same methods for generating cells and other.

table view with multiple columns

i want to display name phone number and salary of a employee in an ipad in the form of table with multiple columns for that i take three table views and successfully displayed data in them . the table views are scrolling independently.but i want to implement if one table view is scrolled the second and third must be moved parallel. can any one please tell me how to implement that one....
If you want all your UITableViews dependants and scrolling at the same time, there is no reason to create multiple table view.
You can just create un custom UITableViewCell with the layout and style you want! This will be easier and will consume less resources.
find out position of cell in first table depending on that change position of cell in next table.
You can use following property of UITableView - – scrollToRowAtIndexPath:atScrollPosition:animated:

Resources