我们正在使用基类来设置背景图片。该代码如下:
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但不想使用背景,我该怎么做?我以为我可以在我的子类'viewDidLoad:
中执行此操作UIView *theBackgroundView = [self.view viewWithTag:BACKGROUND_TAG ];
theBackgroundView = nil;
但这不起作用。有什么想法吗?感谢。
答案 0 :(得分:0)
请务必先致电[super viewDidLoad]
。然后做[[self.view viewWithTag: BACKGROUND_TAG] removeFromSuperview]
。