2012-03-19 59 views
0

我們正在使用設置背景圖片的基類。該代碼看起來像:在viewDidLoad中的子類中設置不同的背景圖像

UIImage* image = [UIImage imageNamed:@"App_Background.png"]; 
UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; 
imageView.contentMode = UIViewContentModeScaleAspectFill; 
CGRect bounds = self.view.bounds; 
int offset = 0; 

imageView.frame = CGRectMake(0, bounds.size.height - image.size.height + offset, image.size.width, image.size.height); 
imageView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin; 
imageView.tag = BACKGROUND_TAG; 
[self.view insertSubview:imageView atIndex:0]; // insert it behind all other views in NIB 

self.background = [imageView autorelease]; // cleanup 

如果我想用這個作爲我的超另一UIViewController的,但不希望使用backgound,我該怎麼辦呢?我認爲我可以在我的子類中做到這一點'viewDidLoad:

UIView *theBackgroundView = [self.view viewWithTag:BACKGROUND_TAG ]; 
theBackgroundView = nil; 

但是這並不奏效。有什麼想法嗎?謝謝。

回答

0

確保您致電[super viewDidLoad]第一個。然後做[[self.view viewWithTag: BACKGROUND_TAG] removeFromSuperview]