Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build a Simple iPhone App (iOS7) Designing your App Programming a Background Image

How can I add a background image to the UITableViewController in Navigation based app?

As explained in the video -

UIImage *background = [UIImage imageNamed:@"background"]; UIImageView *imageView = [[UIImageView alloc] initWithImage:background]; [self.view insertSubview:imageView atIndex:0];

The code works well for my View Controllers. But, need some advice for UITableViewController.

Screenshot - Imgur

2 Answers

Stone Preston
Stone Preston
42,016 Points

maybe try doing something like this in your viewDidLoad method:

UIImage *background = [UIImage imageNamed:@"background"]; 
UIImageView *imageView = [[UIImageView alloc] initWithImage:background]; 
[self.tableView setBackgroundView:imageView];

I havent tested it but it could work

Yes, I tried the same code (via Stackoverflow) and I get 'tableView not found on object of type'. So, the next question would be if I want to use self.tableview where should I declare tableView as my property?

property(nonatomic, strong) IBOutlet UITableView *tableView;

Thanks, Stone for speedy reply.

Stone Preston
Stone Preston
42,016 Points

Ok I assumed you were using a a tableView controller, but it appears you arent. where is your tableView currently being declared and initialized at? you may not have to create a property if you already have a table view being created somewhere