Ios 使用viewDidLoad时的无限循环?
我正在从viewDidLoad初始化一个自定义对象,并从该对象调用addSubview,因此每次它更新时,都会再次调用viewDidLoad。我只是不知道如何修复它,我可能实现addSubview是错误的Ios 使用viewDidLoad时的无限循环?,ios,iphone,objective-c,Ios,Iphone,Objective C,我正在从viewDidLoad初始化一个自定义对象,并从该对象调用addSubview,因此每次它更新时,都会再次调用viewDidLoad。我只是不知道如何修复它,我可能实现addSubview是错误的 SLDViewController.m - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib.
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];
}
然后我从“显示”中调用它:
对象类型为SLDViewController。通过将所有代码从viewDidLoad从SLDViewController移动到SLDAppDelegate DidFinishLaunching,解决了此问题。共享调用AddSubViews的代码。因此,如果您有一个无限循环,循环的代码在哪里?您是否实现了自己的addSubview?另外,您没有实现
addSubview
,您只是在调用它。您得到的无限循环是什么?
- (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 ***");
}