David Omid
David Omid

Reputation: 665

Expand UITableView to full size?

I have a UIViewController. Within it is a UIScrollView with several views inside it. At the bottom is a UITableView.

This UITableView is dynamic and will display either a small number or large number of rows. Either way, I want the UITableView to be displayed full size so the user can scroll down to the bottom of it using the parent UIScrollView, NOT the UIScrollView inside the UITableView.

I've attempted this by disabling scrolling for the UITableView (this works fine). I've then tried at runtime to expand the UITableView so that all rows can be displayed correctly.

However, this part isn't working. For some reason despite the UITableView being really big, not all the rows are being displayed.

I've expanded the UITableView like this:

CGRect frame = tableView.frame;
frame.size.height = 5000;
tableView.frame = frame;

What have I missed? Is there another view inside the UITableView which I need to expand for all the rows to be displayed?

Sorry if this was a silly question, I've only been using iOS for the last month.

Thanks in advance for any help :)


To clarify, this is a screenshot of the problem.

The red area is the UITableView, so it's definitely the correct size. However, there are supposed to be 10 table rows. There are only 5, even less if I increase the size of the table rows.

What do I need to do to display all the rows? What do I need to resize?

enter image description here

Upvotes: 2

Views: 1714

Answers (2)

Cowirrie
Cowirrie

Reputation: 7226

While I see you've managed to get it running, placing a UITableView within your own UIScrollView may mean the table view can't manage its content cells as efficiently as it can when it handles its own scrolling.

But, how can you add your own custom views and have them scroll with the table cells? By making them subviews of the UITableView. If you add one or two subviews to a UITableView, it positions them above and/or below its content, and scrolls them with its own cells.

The screenshot below shows how this looks in the XCode interface editor. Note that the root view is the UITableView, it contains two subviews for the header and footer, and those subviews can contain whatever subviews you need.

XCode interface editor showing subviews of a UITableView

Upvotes: 3

David Omid
David Omid

Reputation: 665

I managed to get it to work fine. However, I have no idea what the problem was in the first place.

I moved the UITableView higher up so it was covering the other views on the page. It displayed fine. I then moved it down to determine what was causing the problems, and it started displaying perfectly.

I'll put it down to an error in where I placed the UITableView, as I can't see any other issues.

Upvotes: 0

Related Questions