Pangu
Pangu

Reputation: 3819

How to scroll to bottom of UITableView to see all cell contents without adjusting cell height?

I am having an issue with my UITableView not being able to scroll past the last cell. It just "bounces" back up. Depending on what iPhone simulation I run, it will bounce back up past 2 cells, so if I run it on a 3.5 inch simulator, the last 2 cells are not reachable.

I have constraints setup with AutoLayout enabled, which is a requirement for me. I have looked at some suggestions on SO, trying some solutions, but so far, it does not work.

I prefer not to set the cell height, if possible.

enter image description here

enter image description here

In the scrolled state when I scroll up, I can see 2 more cells, but once I release the mouse hold, it bounces back up to the normal state with the 2 last cells not in view.

How do I allow the UITableView to be scrolled in a small window frame without adjusting the height, and still be able to see all cell contents?

Upvotes: 1

Views: 497

Answers (2)

Zigii Wong
Zigii Wong

Reputation: 7826

Several problems:

  1. The constraints you had set up were showing warnings. According to you app, you need to fix it by your self;

  2. The bottom cell wasn't visible that is because of the constraints' issue. In you swipeUpMethod method, you need to adjust your constraints. In this case, I set self.markerViewTopVerticalConstraint.constant to -(self.view.frame.size.height/2.5) - 60. So you need to calculate the constraint height according to the number of cells which will display in your tableView.

- (void)swipeUpMethod
{
  [self.view layoutIfNeeded];
 
  [UIView animateWithDuration:0.3
                 animations:^{
                     self.markerViewTopVerticalConstraint.constant = -(self.view.frame.size.height/2.5) - 60;
                     [self.view layoutIfNeeded];
                 }];
  self.swipeMarkerImageView.image = [UIImage imageNamed:@"down_arrow"];
  NSLog(@"self.markersView: %@",self.markersView);
  NSLog(@"self.markersTableView :%@",self.markersTableView);
}

Now, it looks like:

enter image description here

Upvotes: 1

Abhishek Kumar
Abhishek Kumar

Reputation: 324

This is an autolayout problem. Make sure that the autolayout is set correctly. As far as I can understand from seeing your snapshot, the map view's height is constant and the table view's height is changing as per device height. Now to correctly set the autolayout, select the map view and add the following constraints, top, left, Width and height. Make sure to uncheck the "Constrain to margins". Now for the table view use the following auto layout. Add top, bottom left and right constraints. After this, please check in other simulators. Hoppe this helps.

Upvotes: 0

Related Questions