0

I have a scroll view with 3 UITableViews in it for paging. All of the UITableViews loads more cells of data. The first UITableView loads more cells than the other two. When viewing this first UITableView I am able to scroll to the bottom, but when I scroll to a second UITableView and back to the first UITableView I can no longer scroll all the way down. It seems as though I have to resize my scroll view. Why can't I scroll to the bottom after a view refresh? Any help would be great.

*The first UITableView has a search bar at the top. The other two do not. I tried removing the search bar, but the error still occurs.

//Create a frame for each page and add the page to the scroll view
- (void)frameToScrollView{

if (pages!=NULL) {

    for (int i = 0; i < pages.count; i++) {

        //Get the current view controller
        UITableViewController *controller = [pages objectAtIndex:i];

        //Create a frame for the current table view controller
        CGRect frame = controller.view.frame;
        frame.origin.x = self.scrollView.frame.size.width * i;
        frame.origin.y = 0;
        frame.size = self.scrollView.frame.size;
        controller.view.frame = frame;

        //Add the the current table view controller page to the scroll view
        [self.scrollView addSubview:controller.view];
    }
  }
}

Set Other properties:

//Set the properties for the scroll view
- (void)setScrollViewProperties{
     self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * pages.count,     self.scrollView.frame.size.height);
    self.scrollView.contentOffset = CGPointMake(self.scrollView.frame.size.width, 0);
    self.scrollView.scrollsToTop = NO;
}
Vineet Singh
  • 4,009
  • 1
  • 28
  • 39
wwjdm
  • 2,568
  • 7
  • 32
  • 61
  • Have you checked this? http://stackoverflow.com/questions/3422915/scrolling-a-uitableview-inside-a-uiscrollview – Rui Peres Apr 11 '13 at 08:24
  • @Jacky Boy Checking now. No thats not it. I am able to scroll to the bottom but when I load another UITableView and the come back I can only scroll a little bit (maybe the size of the scroll view or the size of one of the other UITableViews). – wwjdm Apr 11 '13 at 08:27

3 Answers3

1

UITableView is a subclass of UIScrollView. So you are basically adding 3 scrollviews to a scrollview. I dont think this is advisable.

I think the problem here is that the device is confused as to which scrollView will handle the touch/drag event.

If you really need the scrollView for paging, I suggest you create the scrollView, but disable touch event for this. You can add buttons to allow page navigation (instead of allowing user to do left/right swipe). This way, you can ensure that only the tableview that is visible is going to get the touch/drag event.

  • 1
    `Some Men Just Want to Watch the World Burn...` – Rui Peres Apr 11 '13 at 08:29
  • I want the 3 scroll views inside a scroll view so that I can scroll left and right while changing a page control. It works, it just wont scroll to bottom after I scroll to another view. – wwjdm Apr 11 '13 at 08:34
  • Can you give more info about your container scrollview? How did you create it and what are the properties that you set? –  Apr 11 '13 at 08:43
  • Scroll view Properties: Paging Enabled, Direction Lock Enabled, Bounces, DElay content touches, cancellable content touches, user interaction enabled, multiple touch, opaque, clears graphic content, clip subviews, autoresize subviews, width:320 height 407 – wwjdm Apr 11 '13 at 08:50
  • Created the scroll view in interface builder and I use IBOutlet UIScrollView *scrollView; – wwjdm Apr 11 '13 at 08:54
  • Are you also alowing vertical scrolling in your scrollview? Try setting your scrollView contentSize.height to exactly the same as your tableView height. –  Apr 11 '13 at 09:02
  • I think the problem is that the device is confused as to what scrollview is going to get the drag event. To debug which one of your scrollviews are getting the event implement the scrollview delegate for your tableViews and scrollview: - (void)scrollViewDidScroll:(UIScrollView *)scrollView. –  Apr 11 '13 at 09:10
  • Vertical scrolling should work. I dont see a setting for that. Also, tried setting scrollview height to tableview height and it didn't work. – wwjdm Apr 11 '13 at 09:13
  • Ok let me implement the scrollViewDidScroll and I'l get back to you – wwjdm Apr 11 '13 at 09:15
  • Ok I implemented the scrollViewDidScroll and when I scroll the UITableView only the UITableView Scrollviewdidscroll is called. What happens is that after I load more items into the tableview and reload the view it will only scrolls as far as it did before I added items. – wwjdm Apr 11 '13 at 09:29
  • You can try removing the tableView, then reload the data, and then adding it again instead of just reloading the tableView data. Also, you can update your question and explain why you need to add the 3 tableviews to a scrollview (for paging). –  Apr 11 '13 at 09:36
  • ok thank you, I'll try this out tomorrow and let you know how it goes. – wwjdm Apr 11 '13 at 09:44
  • How would I go about removing the view. Once they click load more I remove the view? – wwjdm Apr 12 '13 at 17:44
  • Removing the table view is an UGLY solution to your problem (if it indeed solves your problem). Anyway, to remove & add the view again, you have to do it in the view controller that owns the scrollview. Everytime you update your tableview data, you remove it by something like: [theTableViewController.view removeFromSuperview]; [theTableViewController.tableView reloadData] // then you just add your tableView again after reloading the data –  Apr 12 '13 at 17:54
0

Found similar problem here: UITableView Won't Scroll In Certain Conditions.

My first UITableView has a search bar at top.

In the post above they recommend adding [self.tableView setAlwaysBounceVertical:YES];

I tested this and it does not work. I put it in my view did load for the UITableView.

Community
  • 1
  • 1
wwjdm
  • 2,568
  • 7
  • 32
  • 61
0

Got it working:

(1) After "load more" cell is clicked and information is received I remove all subviews
(2) Then I create new frames and add them back to the subview
(3) Last I reload the table data

wwjdm
  • 2,568
  • 7
  • 32
  • 61