简体   繁体   English

UITableViewCell内的UIScrollView-水平滚动

[英]UIScrollView inside a UITableViewCell - horizontal scrolling

I have been trying to set up a UIScrollView within a custom UITableViewCell . 我一直在尝试在自定义UITableViewCell设置UIScrollView 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. 我尝试在自定义.xib文件中添加UIScrollView ,对其进行子类化,还手动将其作为子视图添加到cellForRowAtIndexPath方法中的UITableViewCell中。 In all these, I have set the contentSize of the UIScrollView within cellForRowAtIndexPath . 在所有这些中,我已经在cellForRowAtIndexPath设置了UIScrollViewcontentSize 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. 任何帮助表示赞赏。

Assign a delegate to both table view and the scroll view inside it and make in these(those) delegate(s) implement gestureRecognizer: 将委托分配给表视图和其中的滚动视图,并在这些委托中实现gestureRecognizer:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM