2

I am trying to place a UIImageView behind a the tableView in a view controller that is a subclass of UITableViewController. I have gotten the following code to sort of work, but the image scrolls with the rows in the table.

UIImageView *backgroundView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
[backgroundView setImage:[UIImage imageNamed:@"woodbackground1"]];
[self.view addSubview:backgroundView];
[self.view sendSubviewToBack:backgroundView];
[self.tableView setBackgroundColor:[UIColor clearColor]];

I tried the suggestions in this post Add UIView behind UITableView in UITableViewController code but they produce the same result, am image that across with the table.

Is there a way to place the image view behind the tableview so that the image does not move with the table?

Thanks, Dan

Community
  • 1
  • 1
CatamaranDan
  • 83
  • 1
  • 8

1 Answers1

7

Why not use

self.tableView.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background"]];
agilityvision
  • 7,901
  • 2
  • 29
  • 28
  • 1
    Doing so does not allow the image to scroll along with the view. So this should be what the asker wants. But just a caveat. – akaru Feb 29 '12 at 23:26
  • 1
    Odd. I've tried adding this in viewDidLoad, viewWillAppear and viewDidAppear. Is it also required to set the table and the cell's alphas to < 1? – Alex Zavatone Oct 22 '12 at 18:53