Analysis of the cause of NavigationController's frequent problems in iOS development
- 2020-12-22 17:47:27
- OfStack
Case 1:
MyViewController *sampleViewController = [[[MyViewController alloc]initWithXXX] autorelease];
[self.navigationController pushViewController: sampleViewController animated:true];
BUG: Interface unresponsive
Analyze the possible causes of errors:
1: self.navigationController is nil, null pointer executes pushViewController to skip directly, then sampleViewController will be released, so the interface will be unresponsive.
self. Why is navigationController empty? navigationController is a property inherited from the UIViewController parent class and is not used arbitrarily unless you currently have viewController included by nav push, or xib/code made into navigationcontroller's root. cocoa code should be assigned. (As an aside, many of my interfaces use some ViewController partially. In this case, the nav of viewController is empty. If you want to use it correctly, you can take it from app, assign it yourself, or take the whole interface... Take whatever you want.)
2. self.navigationController is nil, the interface has been suspended
If you use sampleViewController for asynchronous network requests and fetch at initWithXXX, 89 of your 10 will fail.
Analysis of reasons: People network requests, often as follows:
TwitterClient *twitterClient = [[TwitterClient alloc] initWithTarget:self action:@selector(XXXReceive:obj:)];
[twitterClient getXXX:param];
Congratulations, this situation whether or not navigationController is empty, your program is very easy to die, the reason is because we will use asynchronous network request to pull data, when the data comes back, will call back to the class XXXReceive:obj method, but if the interface exits, the data will be received? That's not a null pointer called, TwitterClient records on the memory address to call back anything can be, call back. The tragedy
Solution: twitterClient becomes a member, so do what you want to do with twitterClient when destructing
3, self.navigationController is nil, the interface has been suspended
As the member of twitterClient mentioned above, dealloc also cleaned up the site, but it will still hang
Cause analysis: asynchronous problem, twitterClient has fetched the data, but sampleViewController has been released, but dealloc never got in...
Solution: 1. Make sure nav is correct; 2. Try to request data when viewDidLoad is in the interface and clean up the network when dispear is in the interface.
Situation 2:
reason: 'Pushing a navigation controller is not supported'
The reason for the mistake in the paper is:
As you know, you can put ViewController push into one NavigationController. It's like a push operation!
When sending 1 NavigationController to NavigationController again, error is reported
reason: 'Pushing a navigation controller is not supported' error.
NavigationController does not support push. The object is NavigationController.
The modification is that the page you are going to enter does not inherit from UINavigationController
Case 3:
Sometimes there will be a message push in the project, which will prompt the user with a message, but there is a link in the message. When you click on the link, it cannot jump. This situation is caused by your ES116en. navigationController = nil, because the controller of your popover is not wrapped by UINavigationController