title: Horizontal UIScrollView inside a UITableViewCell
body: <p>I'm trying to create the exact same effect as in the AppStore app for viewing screenshots: inside a UITableView, I have custom subclasses of UITableViewCell's. One of them is designed to show previews of some product, say 4 images. I want them to show the same way as the AppStore presents screenshots of an app : inside a horizontal UIScrollView with its attached UIPageControl.</p>
  
  <p>So I add my UIScrollView and my UIPageControl to my UITableViewCell, just like that :</p>
  
  <pre><code>@implementation phVolumePreviewCell
  - (id)init {
      if (self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kVolumePreviewCellIdentifier]) {
          [self setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
          [self setSelectionStyle:UITableViewCellSeparatorStyleNone];
  
          previews = [[NSMutableArray alloc] initWithCapacity:4];
          for (int i = 0; i &lt; 4; i++) {
              [previews addObject:@"dummy"];
          }
  
          scrollView = [[UIScrollView alloc] initWithFrame:CGRectZero];
          [scrollView setPagingEnabled:YES];
          [scrollView setBackgroundColor:[UIColor grayColor]];
          [scrollView setIndicatorStyle:UIScrollViewIndicatorStyleBlack];
          [scrollView setShowsHorizontalScrollIndicator:YES];
          [scrollView setBounces:YES];
          [scrollView setScrollEnabled:YES];
          [scrollView setDelegate:self];
          [self.contentView addSubview:scrollView];
          [scrollView release];
  
          pageControl = [[UIPageControl alloc] initWithFrame:CGRectZero];
          [pageControl setNumberOfPages:[previews count]];
          [pageControl setBackgroundColor:[UIColor grayColor]];
          [self.contentView addSubview:pageControl];
          [pageControl release];
      }
      return self;
  }
  </code></pre>
  
  <p>(note: I'm populating "previews" with dummy data here, just in order to have a [previews count] that works ; I want to view the scrollView's scroll indicator for test purposes only, I'll hide them later on).</p>
  
  <p>My problem is that I can scroll the whole UITableView containing this phVolumePreviewCell (subclass of UITableViewCell), but I can't scroll the UIScrollView. How can I achieve this?</p>
  
  <p>The only information I found is there: <a href="http://theexciter.com/articles/touches-and-uiscrollview-inside-a-uitableview.html" rel="noreferrer">http://theexciter.com/articles/touches-and-uiscrollview-inside-a-uitableview.html</a>
  But it talks of old SDKs (namely 2.2) and I'm sure there is a more "recent" approach to doing this.</p>
  
  <p>Some precisions :</p>
  
  <ul>
  <li>I can scroll the UIScrollView with two fingers. That's not what I want, I want it to be able to scroll with one finger only.</li>
  <li>When I scroll with two fingers, the TableView still intercepts the touches and scroll a little bit to the top or the bottom. I'd like the TableView to stick at its position when I touch the ScrollView.</li>
  </ul>
  
  <p>I believe I have to work out how to intercept touches on my TableView, and if the touch is on the phVolumePreviewCell (custom UITableViewCell subclass), pass it to the cell instead of handling it on the TableView.</p>
  
  <p>For the record, my TableView is created programmatically in a UITableViewController subclass:</p>
  
  <pre><code>@interface phVolumeController : UITableViewController &lt;UITableViewDelegate&gt; {
      LocalLibrary *lib;
          NSString *volumeID;
          LLVolume *volume;
  }
  
  - (id)initWithLibrary:(LocalLibrary *)newLib andVolumeID:(NSString *)newVolumeID;
  @end
  </code></pre>
  
  <p> </p>
  
  <pre><code>@implementation phVolumeController
  
  #pragma mark -
  #pragma mark Initialization
  
  - (id)initWithLibrary:(LocalLibrary *)newLib andVolumeID:(NSString *)newVolumeID {
      if (self = [super initWithStyle:UITableViewStylePlain]) {
          lib          = [newLib retain];
          volumeID     = newVolumeID;
          volume       = [(LLVolume *)[LLVolume alloc] initFromLibrary:lib forID:volumeID];
          [[self navigationItem] setTitle:[volume title]];
      }
      return self;
  }
  
  - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
      return 1;
  }
  
  - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
      return 1;
  }
  
  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
      UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kVolumePreviewCellIdentifier];
      if (cell == nil) {
          cell = [[[phVolumePreviewCell alloc] init] autorelease];
      }
  
      [(phVolumePreviewCell *)cell setVolume:volume];
      return (UITableViewCell *)cell;
  }
  
  - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
      return kVolumePreviewCellHeight;
  }
  </code></pre>
  
  <p>Thanks for any help!</p>