0

I have a strange issue and I am not sure what is causing it. I have a horizontal scroll view which has an unknown width (paging is enabled):

myScrollView.contentSize = CGSizeMake(320 * count, myScrollView.frame.size.height);

Inside this scroll view is a single table (myTable) which updates depending what the current page is. In the scrollViewDidScroll method - the int page is set, pageControl (UIPageControl) is updated and then I shift the table so that it is still in view. After moving the table I update the data and reload the table.

- (void)scrollViewDidScroll:(UIScrollView *)sender {
CGFloat pageWidth = myScrollView.frame.size.width;
page = floor((tableScroll.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
pageControl.currentPage = page;

[myTable setFrame:CGRectMake(tableScroll.contentOffset.x, 0, 320, 213)];
//[myTable bringSubviewToFront:tableScroll];
//[tableScroll bringSubviewToFront:self.view];

[self getMyData];
[myTable reloadData];

This works fine and the table is visible after scrolling and the data has been updated. The issue I am having is that all interactivity of the table is lost. I cannot click any buttons on the cell or click the cell itself. Interaction is only working on the very first page.

Does anyone know what may be causing this or how to solve it. Cheers

Patrick
  • 6,495
  • 6
  • 51
  • 78
  • try adding a button, and see if same happens with it too. Should help us to get into right direction. – Vaibhav Tekam Jul 24 '12 at 10:10
  • I have an NSLog in the didSelectRowAtIndexPath to test the table. I created a button, also in the UIScrollView, and put the exact same code as the table and that still works. `[testButton setFrame:CGRectMake(tableScroll.contentOffset.x, 0, testButton.frame.size.width, testButton.frame.size.height)];` – Patrick Jul 24 '12 at 10:18
  • There is also a button inside the table cell but that does not work after a page swipe - only ever on the first page (and when returning to the first page) – Patrick Jul 24 '12 at 10:24

1 Answers1

0

I assume that "myTable" is a UITableView. If so I know the problem - the UITableView itself is a subclass of UIScrollView - so you have nested scrollViews. There are workarounds to this UIScrollView in a scrollView. Search on UIScrollView in a scrollView on this site for more suggestions.

Community
  • 1
  • 1
David H
  • 40,852
  • 12
  • 92
  • 138
  • "myTable" is indeed a UITableView. The funny thing is, the table view is in a view which is in the scroll view - so everything is working fine... until the user scrolls. The table is only working when it is in the first page - not when it shifts – Patrick Jul 24 '12 at 13:28
  • So scrollView -> view -> tableView (myTable). Why don't you change the size of the "view" as the scrollView pages, then update the tableView frame (origin) then its contentOffset. I'm thinking your tableView is actually outside the frame of the enclosing view thus not getting touches. You could add a gesture recognizer to the "view" and log some kind of touch to verify the view is getting touches as you scroll. – David H Jul 24 '12 at 13:54
  • Oh my!! Thank you - your answer gave me the method to fix it. It was really stupid - the containing view was not an IBOutlet and its width was fixed at 320px. I just have to make the uitableview's containing view the same width as the uiscrollview. – Patrick Jul 24 '12 at 14:06