简体   繁体   中英

UITableViewCell with UIScrollView cause content of other cells disappearing

I was trying to find solution almost everywhere, but I didn't find it. So, here is my problem.

I have UITableView with custom UITableViewCells.

  1. The first cell has UIScrollView inside its Content View.
  2. The Second cell has UILables and other basic views inside its Content View.

So, if there is UIScrollView inside the first cell, content of the second cell disappears. It appears only if the first cell scrolls out of the tableView frame.

Can anybody help me figure it out? Thank you.

Code preview

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

视图层次

使用UIScrollView的单元格下面的单元格中的内容消失了

单元格与UIScrollView的连接

iOS 7.1上的单元格绘制可能会出现问题,请根据iOS 7.1 beta5 tableviewcell高度上的答案显示超出其范围的对象 ,尝试剪切子视图:

cell.clipsToBounds = YES;

Try it

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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