pachun
pachun

Reputation: 920

Cells disappear when i change the UITableView background

tableView.backgroundColor = UIColor.clearColor
tableView.separatorStyle = UITableViewCellSeparatorStyleNone

background = UIImageView.alloc.initWithImage( UIImage.imageNamed "soft.png" )
tableView.addSubview( background )
tableView.sendSubviewToBack( background )

This is what I'm using to change the background of my table view (grouped style). When I do it this way, the section titles remain, but the table view cells all disappear... What the heck is going on? How can I fix this?

Also, when I scroll I can see black bounce in and out of the screen, which is ugly. This is not my primary problem, but I feel like a solution to the first problem may also fix this one...

Help appreciated.

Upvotes: 0

Views: 164

Answers (2)

Dima
Dima

Reputation: 23634

You don't need to add a subview to get a background image. UITableView already has a backgroundView property that you can just set.

UIImageView *background = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"whatever.png"]];
self.tableView.backGroundView = background;

Upvotes: 1

Justin Paulson
Justin Paulson

Reputation: 4388

Instead of

tableView.addSubview( background );
tableView.sendSubviewToBack( background );

use

[tableView setBackgroundView:background];

Upvotes: 1

Related Questions