ios - UITableViewCell 内的 UIScrollView - 水平滚动

标签 ios uitableview uiscrollview ios7

我一直在尝试设置一个 UIScrollView在定制内 UITableViewCell .我试过添加 UIScrollView自定义内.xib文件,将其子类化并手动将其作为 subview 添加到 UITableViewCellcellForRowAtIndexPath方法。在所有这些中,我设置了 contentSizeUIScrollViewcellForRowAtIndexPath 内.但是无论采用哪种方法,我都无法使其水平滚动。这里有一些代码可以给你一个想法。

- (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];

}

知道我哪里出错了吗?感谢您的帮助。

最佳答案

为 TableView 和其中的 ScrollView 分配一个委托(delegate),并在这些委托(delegate)中实现gestureRecognizer:

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

关于ios - UITableViewCell 内的 UIScrollView - 水平滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20198550/

相关文章:

ios - iOS4 上的 NSFetchedResultsController 问题

ios - 如何在 UIScrollView 中临时隐藏非事件页面

iphone - 购买时重复方法

iphone - 基于 Cordova 的应用程序不是新项目的选项

ios - 更改 UITextField 宽度?

iphone - 导航 Controller 溢出

iphone - 在 UITableView 上延迟重新加载数据

ios - 在后台使用 NSFetchedResultsController 自动 UITableView

ios - 使用 UIScrollView 的渐变背景颜色

ios - UIView 不会垂直滚动到 UIScrollView 内