带有UIScrollView的UITableViewCell导致其他单元格的内容消失

时间:2014-03-11 09:01:57

标签: ios objective-c uitableview uiscrollview

我试图在几乎所有地方找到解决方案,但我没有找到它。所以,这是我的问题。

我有自定义UITableViewCells的UITableView。

  1. 第一个单元格在其内容视图中包含UIScrollView。
  2. 第二个单元格在其内容视图中包含UILables和其他基本视图。
  3. 因此,如果第一个单元格中有UIScrollView,则第二个单元格的内容会消失。仅当第一个单元格滚出tableView框架时才会出现。

    任何人都可以帮我搞清楚吗?谢谢。

    代码预览

    #pragma mark - UITableView Data Source
    
    -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
        if ([indexPath isEqual:_photosIndexPath]) {
            static NSString *PhotosCellIdentifier = @"AdDetailsPhotosCell";
            BazarAdDetailPhotosCell *cell = [tableView dequeueReusableCellWithIdentifier:PhotosCellIdentifier];
            if (!cell) {
                cell = [[BazarAdDetailPhotosCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:PhotosCellIdentifier];
            }
            cell.photoScrollView.scrollsToTop = NO;
            cell.photoScrollView.delegate = cell;
    
            [cell setPhotos:_adDetail.photos];
    
            return cell;
        }
        else if ([indexPath isEqual:_adDetailsPath]) {
            static NSString *DetailsCellIdentifier = @"AdDetailsDetailCell";
            BazarAdDetailsDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:DetailsCellIdentifier];
            if (!cell) {
                cell = [[BazarAdDetailsDetailCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:DetailsCellIdentifier];
            }
    
            cell.adTitleLabel.text = _adDetail.title;
            cell.priceLabel.text = _adDetail.price;
            // this cell content disappears
        }
    }
    

    View hierarchy

    Content in cells below cell with UIScrollView disappears

    Connections of the Cell with UIScrollView

2 个答案:

答案 0 :(得分:3)

根据iOS 7.1 beta5 tableviewcell height showing objects outside it's range的回答,可能会在iOS 7.1上使用单元格绘制出现问题,尝试剪切子视图:

cell.clipsToBounds = YES;

答案 1 :(得分:0)

试试吧

  #pragma mark - UITableView Data Source

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    if ([indexPath isEqual:_photosIndexPath]) 
{
        static NSString *PhotosCellIdentifier = @"AdDetailsPhotosCell";
        BazarAdDetailPhotosCell *cell = [tableView dequeueReusableCellWithIdentifier:PhotosCellIdentifier];
        if (!cell) {
            cell = [[BazarAdDetailPhotosCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:PhotosCellIdentifier];
        }
        cell.photoScrollView.scrollsToTop = NO;
        cell.photoScrollView.delegate = cell;

        [cell setPhotos:_adDetail.photos];

        return cell;
    }
    else  {
        static NSString *DetailsCellIdentifier = @"AdDetailsDetailCell";
        BazarAdDetailsDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:DetailsCellIdentifier];
        if (!cell) {
            cell = [[BazarAdDetailsDetailCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:DetailsCellIdentifier];
        }

        cell.adTitleLabel.text = _adDetail.title;
        cell.priceLabel.text = _adDetail.price;
        // this cell content disappears
 return cell;
    }
}