Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView appearance with ios5 UIAppearance not working correctly?

I'm trying to set the background for a number of UITableViews that are loaded inside a UINavigationController. I'm using the appearance proxy added in iOS 5 but it's not working how I'm expecting it to.

The app uses a UISplitViewController, with the master view being the UINavigationController. Inside this, I have a UITableViewController subclass called PBMasterTableViewController. In my AppDelegate I have the following :

    UIImageView *bgView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"menuBg.png"]] autorelease];
    [[UITableView appearanceWhenContainedIn:[PBMasterTableViewController_Ipad class], nil] setBackgroundView:bgView];

This is working fine, and my main menu in the split view has the background that I want.

From this main menu, I 3 other UITableViewController sublasses that are pushed onto the nav controller when I select the relevant rows. I cannot however get the background of these tables to change using the appearance proxy. I'm trying the following :

    UIImageView *bgView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"menuBg.png"]] autorelease];
    [[UITableView appearanceWhenContainedIn:[PBTwitterTableViewController class], nil] setBackgroundView:bgView];

This is also in the appDelegate right below the code previously shown that works (without the repetition of the image view creation however) but this simply does nothing! When I push an instance of the PBTwitterTableViewController onto the nav controller, I simply get a standard table view with no background change.

I know that I could simply change the background views in the tableViewControllers themselves, however I don't want these backgrounds to be there when the menu is shown in the splitViewControllers popover when rotated to portait, hence I am trying to use appearanceWhenContainedIn:

I also don't want to simply set the appearance to be when contained in the UISplitViewController, as in 2 instances I have a UITableView being loaded into the detail section, so this would then change the appearance of those which I do not want.

Is there another way of doing this without the appearance proxy that will still allow me to change the background for when it is in the popover, or is there a way of making this work with the proxy, or am I just missing something stupid?

Thanks

EDIT :

I've just tried creating a subclass of the UINavigationController and tried using [[UITableView appearanceWhenContainedIn:[PBMenuNavigationController class], nil] setBackgroundView:bgView]; which is again working fine for the main menu, but not for any other UITableView pushed onto the stack, so I'm really stumped now :(

like image 548
PaReeOhNos Avatar asked Nov 13 '22 08:11

PaReeOhNos


1 Answers

OK sorted it. Just doing it inside each view and checking that the parent controller isn't something that I don't want. Thanks anyway

like image 102
PaReeOhNos Avatar answered May 30 '23 21:05

PaReeOhNos