UIScrollView inside a UITableViewCell - horizontal scrolling

倖福魔咒の 提交于 2020-01-06 12:42:11

问题


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.


回答1:


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; }


来源:https://stackoverflow.com/questions/20198550/uiscrollview-inside-a-uitableviewcell-horizontal-scrolling

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!