Stephen J
Stephen J

Reputation: 2397

Setting background to transparent on Custom UITableViewCell iOS 5 not working, none of the tricks are working

So, this title probably makes me look new and like I haven't looked for answers here, so first, let me state that: I did already check for answers on setting the background to transparent, as well as selection to custom (also not working).

My point: I created a custom table view cell, set everything to transparent, but nothing was transparent.

So I looked here, looped through all the subviews, their subviews, and the cell.backgroundColor and set it to transparent.

I implement the -(tableView*)willDisplayCell method and did the recommended steps, still not transparent.

I messed with the setSelected: callback method, doing the recommended along with setting the subviews to transparent.

Now I must thank Apple for a white background.

So I eventually just plugged in an image view with a similar color. I would prefer not to use that method.

I set the type to a custom table view cell, (in the Xib, I chose "Custom" in the drop down on the main view properties on the right).

Here's my code: [code] (sorry about formatting, StackOverflow says the tab key will do it... in a browser...)

 if (cell == nil) {

        NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"TheCustomTableViewCellTableViewCell" owner:self options:nil];

        // Grab a pointer to the first object (presumably the custom cell, as that's all the XIB should contain).

        cell = [topLevelObjects objectAtIndex:0];

       // Load the top-level objects from the custom cell XIB.

        TheCustomTableViewCell * customCell = (TheCustomTableViewCell*)cell;

        customCell.titleTextLabel.text = item.title;

//This is Matt Gallagher 's answer modified but isn't working       

cell.selectedBackgroundView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)] autorelease];

        cell.selectedBackgroundView.backgroundColor = [UIColor redColor];

[/code]

Final note, I've tried hooking up different views inside my Xib as "The backgroundView" and setting those to transparent, as well as create my own, curious if there's a specific way I have to do that to get it to finally be transparent.

I have a feeling recursively looping through every single view is not the best solution, and probably wouldn't work.

It could just be I need to reboot the computer, but I've already cleaned the build and restarted XCode 4.

Any help would be greatly appreciated... I'm in Xcode 4 iOS 5, the one that makes having dual monitors pointless by stripping all your edit functions out of the Xib editor if you try to edit it in the other window! Just to be specific. Also, the install is fresh, I don't have the iOS 4 emulator, will grab it soon and see if it's version issues

Upvotes: 3

Views: 5284

Answers (1)

Shmidt
Shmidt

Reputation: 16684

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Background.png"]];
...
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
cell.backgroundColor = [UIColor clearColor];
...
}

Upvotes: 2

Related Questions