- viewDidLoad infinite loop problem ... (iOS)

I am trying to write a multi-user application in iOS and it’s really a little hard ... I have set up a new project and I have rootViewController running appDelegate. In turn, the rootViewController is trying to load and display my first view of the content, although I seem to have gotten into some kind of endless loop, I hope someone here may have a hunch why ...

-(void)viewDidLoad { // Load up new instance of view TopLevelViewController *topLevelController = [[TopLevelViewController alloc] initWithNibName:@"TopLevelView" bundle:nil]; // Hand off viewController reference to root controller self.topLevelViewController = topLevelController; // Display the view [self.view insertSubview:topLevelController.view atIndex:0]; // Release viewController [topLevelController release]; [super viewDidLoad]; } 

Above is my viewViewDoadLoad method: my rootViewController, although every time it executes insertSubview it returns to the top and does it all again. I am a little confused since I based this code almost the same on the tutorial I followed and it worked beautifully ... which makes me think that the problem should be in another place, although I could not think where.

Appreciate any understanding!

+4
source share
8 answers

I just realized that I never closed it after a recent interest.

As I recall, @Wolfgang Schreurs is exactly true. For some reason, experimenting with code, I had topLevelViewController inheriting from rootViewController .

Hope this helps everyone who might run into the same problem.

+1
source

I ran into the same problem and took some time to understand.

When self.view does not exist, iOS will call loadview / viewdidload and try to create the view. this causes a dead position. In my case, I did not call [super loadView] in my loadView and caused this problem.

See this discussion http://forums.macrumors.com/showthread.php?t=552520

+14
source

Set a breakpoint on viewDidLoad , continue several times, then take a backtrace and publish it.

Also add NSLog(@"%@ self is %p", NSStringFromSelector(_cmd), self); to the top of your viewDidLoad . Perhaps you created a kind of configuration of nib files with "endless mirrors"; if the hexadecimal number continues to change, these will be different instances of your representation.

+5
source

I know this sounds easy, but try moving around

 [super viewDidLoad] 

to the top of your code. I have a feeling that super should be the first thing you need to call.

+2
source

Try [self.view addSubview:topLevelController.view]

0
source

Set a breakpoint and see where your loop works ...

0
source

I deleted the loadView method and it fixed it for me, if you have this method in your .m file, delete it!

0
source

This also happens if you create @property (nonatomic, strong) UIView *loadView and access it in viewDidLoad You must rename the property.

0
source

Source: https://habr.com/ru/post/1339576/


All Articles