petesalt
petesalt

Reputation: 356

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

View hierarchy

Content in cells below cell with UIScrollView disappears

Connections of the Cell with UIScrollView

Upvotes: 0

Views: 1006

Answers (2)

tyorke
tyorke

Reputation: 46

Might be issue with cell drawing on iOS 7.1, according answer on iOS 7.1 beta5 tableviewcell height showing objects outside it's range, try to clip subviews:

cell.clipsToBounds = YES;

Upvotes: 3

Muralikrishna
Muralikrishna

Reputation: 1044

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

Upvotes: 0

Related Questions