1

The title might not be so clear but it was really hard to express it so I will do my best to explain here.

Look at this image:

enter image description here

I want the UITableView to stop entirely after all the rows are done. Meaning after the footer there should be no more white view.

I think what is causing this is the constraints that i have put. But I need my constraints to make it look good in all possible sizes etc. So my question is how can something like this be solved? I am using SWIFT.

Bhavin Ramani
  • 3,221
  • 5
  • 30
  • 41
Timo Cengiz
  • 3,367
  • 4
  • 23
  • 45
  • 1
    Try give your `tableview.backgroundColor = UIColor.clearColor` and `cell.backgroundColor = UIColor.whiteColor` Programatically. – Nirav D Jun 17 '16 at 12:56
  • This actually worked fine. Thank you for this sneaky method. But learning a way to do it properly would be nicer. But love your answer @NiravDoctorwala – Timo Cengiz Jun 17 '16 at 13:00
  • Maybe answer for this [question](http://stackoverflow.com/questions/2595118/resizing-uitableview-to-fit-content) will help. – tahavath Jun 17 '16 at 13:02

5 Answers5

1

This worked like a charm. Thank you @tahavath for pointing me to this direcation

override func viewWillLayoutSubviews() {

    dispatch_async(dispatch_get_main_queue(),{
        //This code will run in the main thread:
        var frame = self.tableView.frame;
        frame.size.height = self.tableView.contentSize.height;
        self.tableView.frame = frame;
    });
}

EDIT

It does work however this will be a problem if the table is bigger than the screen. When trying to run this on iphone 4s it looked terrible.

Timo Cengiz
  • 3,367
  • 4
  • 23
  • 45
  • You can add output screen for clarity future visitors of the post. That would be helpful. – viral Jun 17 '16 at 14:17
0

Try the following code... Just include the following code... give your table view an automatic dimension.

override func tableView(tableView: UITableView!, heightForRowAtIndexPath indexPath: NSIndexPath!) -> CGFloat {
    return UITableViewAutomaticDimension;
}

Also add the following code where the view loads

tableView.estimatedRowHeight = 89
tableView.rowHeight = UITableViewAutomaticDimension
0

Why don't you set

tableView.backgroundColor = UIColor.clearColor()

and then you set

cell.backgroundColor = UIColor.whiteColor()

Edit (not sneaky approach)

tableView.frame.size.height = tableView.contentSize.height

But there is a problem, if the screen height is not enough to contain tableView content, it will be bad.

Here's the right way

tableView.frame.size.height = 
    tableView.contentSize.height > UIScreen.mainScreen().bounds.height ? UIScreen.mainScreen().bounds.height : tableView.contentSize.height
Edward Anthony
  • 3,354
  • 3
  • 25
  • 40
-1

Because the table thinks there is a footer to show, it doesn't display any cells beyond those you explicitly asked for.

Set a zero height table footer view in your viewDidLoad method

self.tableView.tableFooterView = UIView(frame: CGRectZero)

Or

tableView.tableFooterView = UIView()
Bhavin Ramani
  • 3,221
  • 5
  • 30
  • 41
-1
override func viewDidLoad() {
    super.viewDidLoad()
    self.tableView.tableFooterView = UIView()
}
Bhadresh Mulsaniya
  • 2,610
  • 1
  • 12
  • 25