我正在从viewDidLoad初始化一个自定义对象并从该对象调用addSubview,因此每次更新时,都会再次调用viewDidLoad。我只是不知道如何修复它,我可能实现了addSubview错误。
SLDViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
SLDSlide *slide1 = [[SLDSlide alloc] initWithImage:@"building-demolition4.gif" numFrames:60 frameWidth:417 totalWidth:25020 height:238];
[slide1 display];
}
然后我从“显示”中调用它:
- (void) display {
CGImageRef imageRef = CGImageCreateWithImageInRect(self.image.CGImage, CGRectMake(0, 0, self.frameWidth, self.height));
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake((screenWidth - _frameWidth)/2, (screenHeight - _height)/2, _frameWidth, _height)];
imageView.userInteractionEnabled = YES;
imageView.image = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
[self.view addSubview:imageView];
NSLog(@"*** Displayed ***");
}
该对象的类型为SLDViewController。
答案 0 :(得分:0)
通过将所有代码从viewDidLoad从SLDViewController移动到SLDAppDelegate DidFinishLaunching来修复此问题。