0

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).

enter image description here

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

enter image description here

Any help and suggestions are highly appreciated. Thanks.

9
  • 2
    Why you don't use one UITableView for all your content? Commented Dec 19, 2016 at 11:57
  • 2
    ^exactly, use one tableview with all sorting logic in one array as you see fit. The half desc and asc part can be managed by breaking the array into two and sorting then joining or using keys to sort it half way around. but your work will get very easy once you manage the DS Commented Dec 19, 2016 at 11:59
  • 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 Commented Dec 19, 2016 at 11:59
  • You can use only one but with Sections! Commented Dec 19, 2016 at 12:03
  • @MagoNicolasPalacios Each table has sections already. =D Commented Dec 19, 2016 at 12:04

1 Answer 1

2

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:

  1. two separated array for the data that you've wanted to be ordered descending and one for ascending.
  2. 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.
  3. 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.
  4. 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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the reply @Axel. I agree with your answer. =D

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.