0

I've got a UITableView which is shown in a UIView - the reason I've done this is that I want to place a solid rectangle over the table (with CGContextSetBlendMode kCGBlendModeMultiply) and continuously change its colour, so I get the effect of the table's text continuously changing colour. I can't think of any other way of doing this, but the problem I have is that the coloured rectangle always appears below the table and sits solidly on top of (or below if I change the order of the subviews) the other UIViews. It doesn't seem to have any effect on the table no matter what I do. Is there any way of changing the display order within the UIView? The table is connected from IB. I'm not sure what other info I need to post for anyone who might be able to answer! Thanks very much for any help.

SomaMan
  • 4,127
  • 1
  • 34
  • 45

1 Answers1

0

In order to cover your TableView with another UIView, the covering UIView must have a sibling relationship with the TableView or with one of the ancestors of the TableView. If the TableView is "shown in a UIView", that UIView that it's shown in can never obscure the TableView. Child views always obscure parent views. Create another UIView inside the "shown in UIView", it will then be a sibling view to the TableView, and can be put on top of it. Like this:

UIView *parentView = [[UIView alloc] initWithFrame:parentFrame];
UITableView *tableView = [[UITableView alloc] // table create parameters....
[parentView addSubiew:tableView];
UIView *obscuringView = [[UIView alloc] initwithObscuringFrame];
[parentView addSubView:obscuringView];

The obscuring view will then sit on top of the table view.

Bogatyr
  • 19,255
  • 7
  • 59
  • 72
  • Thanks! That appears to have cracked it! Looks so easy when you know how... weirdly tho, when I copied & pasted the code it kept coming up with "[ScoresView addSubView:]: unrecognized selector sent to instance", which was making me tear my hair out! Turns out there were hidden characters in the string I copied from my browser, only realised when I typed in "insertSubView:" manually... – SomaMan Feb 10 '11 at 14:09