Rameez Hussain
Rameez Hussain

Reputation: 6754

UIScrollView inside a UITableViewCell - horizontal scrolling

I have been trying to set up a UIScrollView within a custom UITableViewCell. I have tried adding a UIScrollView within the custom .xib file, subclassing it and also manually adding it as a subview to the UITableViewCell in the cellForRowAtIndexPath method. In all these, I have set the contentSize of the UIScrollView within cellForRowAtIndexPath. But regardless of the approach, I have been unable to make it scroll horizontally. Here is some code to give you an idea.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *CellIdentifier = @"Custom_Cell";
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    CellIdentifier = @"Custom_Cell";
    }

CustomCell *cell = (CustomCell *)[self.fpTable dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {

    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:CellIdentifier owner:nil options:nil];
    // cell = [nib objectAtIndex:0];

    for(id currentObject in nib)

    {

        if([currentObject isKindOfClass:[CustomCell class]])

        {
            cell = (CustomCell *)currentObject;

            break;
        }
    }

    cell.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
}

[cell.pgCellScroll setContentSize:CGSizeMake(160*3 + (5*4), 160)];

[cell.pgCellScroll setScrollEnabled:YES];

[cell.pgCellScroll setDelaysContentTouches:YES];
[cell.pgCellScroll setCanCancelContentTouches:NO];

}

Any idea where I am going wrong? Any help is appreciated.

Upvotes: 0

Views: 3802

Answers (1)

johnyu
johnyu

Reputation: 2151

Assign a delegate to both table view and the scroll view inside it and make in these(those) delegate(s) implement gestureRecognizer:

 - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer
 *)otherGestureRecognizer {
     return YES; }

Upvotes: 1

Related Questions