views:

59

answers:

2

Hi!

I want to have transparency between UITableViewCells. Space between the cells.

I user custom created cells and for setting a background i use this code:

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

    static NSString *CustomCell = @"CustomBookingCell";

    currentBooking = [arrayBookings objectAtIndex:indexPath.row];

    CustomBookingCell *cell = (CustomBookingCell *)[tableView dequeueReusableCellWithIdentifier:CustomCell];

    if (cell == nil) {

        UIViewController *c = [[UIViewController alloc] initWithNibName:@"CustomBookingCell" bundle:nil];
        cell = (CustomBookingCell *)c.view;
        [ c release ];
    }



    bookingImage = [[UIImageView alloc] initWithImage:
                     [UIImage imageNamed:currentBooking.imageSource]];

    [cell.imageForBooking addSubview:bookingImage];
    cell.selectionStyle = UITableViewCellSelectionStyleGray;
    cell.contentView.backgroundColor = [UIColor clearColor];


    UIView* backgroundView = [[UIView alloc] initWithFrame:CGRectZero];
    UIImage* bgImage = [UIImage imageNamed:@"Background_300_82.png"];
    UIColor *bgColor = [[UIColor alloc] initWithPatternImage: bgImage];

    backgroundView.backgroundColor = bgColor;
    cell.backgroundView = backgroundView;
    cell.label.text = currentBooking.title;

    [bookingImage release];
    [bgColor release];
    [backgroundView release];


    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 90;
}

The height of the cell is 10 pixels higher that the tableCellBg.png. My background view has also a image as background (this background is supposed to be shown between the cells of course).

So I tried to add 10 pixels with transparency to my tableCellBg.png in the bottom to fix this. But the space between the cells is black. I can't see the view background between my cells.

What shall I do? Do I have to create a UIView in cellForRowAtIndexPath with the height of the tableCellBg.png and then add the Custom UITableViewCell as subview to the created UIView with a less higher height?

Or is there a much more simplyfied way to accomplish this?

+3  A: 

Your table view needs a clear background colour. For example

myTableView.backgroundColor = [UIColor clearColor];
mbehan
I was just answering the same so I voted it up instead.
Echelon
I'm sorry I didn't mentioned that I have already that code.
Fernando Redondo
What else can I try?
Fernando Redondo
Can you edit the question to show more of your code?
mbehan
The background images is by the way 82 pixels height.
Fernando Redondo
A: 

I solved it by using another method to add the background image to the UITableViewCell:

    UIImage *image = [UIImage imageNamed:@"ny_bg_event.png"];
UIImageView  *imageView = [[UIImageView alloc] initWithImage:image];
imageView.frame = CGRectMake(0, 0, 300, 84);
cell.backgroundView = imageView;
cell.backgroundColor = [UIColor clearColor];
[imageView release];

[cell setFrame:CGRectMake(0, 0, 300, 84)];

cell.contentView.backgroundColor = [UIColor clearColor];

Instead of creating a UIView I just used a UIImageView instead.

Fernando Redondo