Question

@All Hello

Its quite interesting problem i have. Actually i have subviews which can be larger in height then cell height itself (Its required for my design). For example cell "A" height is 40 while subview height= 70.

I can show larger subview but when the cell A goes off the screen (i scroll to top) then its subview also disappear (Obvious) result. But that gives undesired effect as larger subview which before extends to cell say "B" beneath container cell suddenly disappear.

I have tried to set cell background as transparent in willDisplayCell delegate method but no luck.

Below is my related method if anyone wants to see

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *MyIdentifier = @"MyIdentifier";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:nil];

if (cell == nil)
{
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                   reuseIdentifier:MyIdentifier] autorelease];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
}

NSArray *newArray = [[dataDictionary allKeys] sortedArrayUsingSelector: @selector(compare:)];

[cell.contentView addSubview: [[[dataDictionary objectForKey:[newArray objectAtIndex:indexPath.section]] objectForKey:@"DayView"] objectAtIndex:indexPath.row]];

return cell;
}

Pardon me if i am not very much clear but this is best i can explain my situation.

I want to show views like http://postimg.org/image/e5ok5hybl/ image.

Was it helpful?

Solution

If you must do this, you can use a simple trick:

  1. Move the y-origin of the table to a negative value equal to the amount your view extends below the cell, e.g. origin -30px.
  2. Make the table height taller by the same amount, i.e. make it 30px taller.
  3. Increase the top content inset of the table by the same amount, i.e. increase by 30px.

What you've effectively done is extend the table view off-screen while maintaining the original position of the cells. Since the table view extends off-screen, the cell will not be dequeued until the part that extends below the cell has scrolled off screen.

Here is a sample project demonstrating the trick.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top