OC Learning Path----Application.keyWindow.rootViewController and Self.window.rootViewController and [Self.window Makekeyandvisible]; Small discoveries

Source: Internet
Author: User

While debugging just a few small problems, there is a piece of code to reuse

NSString *key =@"cfbundleversion"; //Remove the version number of the last-used software stored in the sandboxNsuserdefaults *defaults =[Nsuserdefaults Standarduserdefaults]; NSString*lastversion =[Defaults Stringforkey:key]; //Remove the current version numberNSString *currentversion =[NSBundle Mainbundle].infodictionary[key]; Etlog (@"%@===%@=================", Self.window,application.keywindow); if([lastversion isequaltostring:currentversion]) {Application.keyWindow.rootViewControl Ler=[[Ettarbarcontrollor alloc] init]; }            Else{Application.keyWindow.rootViewController=[[Newfeatureviewcontroller alloc] init];                [Defaults setobject:currentversion Forkey:key];            [Defaults synchronize]; }

It was supposed to be extracted and then used in the tool class [uiapplication sharedapplication]. Keywindow. Rootviewcontroller replaces the original self. Window. Rootviewcontroller, but found that with the real machine debugging when the black screen, not normal display, I felt strange at that time, is not the location of the code to change, and then I put appdelegate self. Window. Rootviewcontroller Replace

application. Keywindow. Rootviewcontroller, found or not, I that depressed ah, later the same code I run on the virtual machine, Mom eggs, can run, I must be on the real machine debugging, so, I went back to the real machine, I application. Keywindow and self. Window Print out, note that this is on the real machine and found appapplication. Keywindow is empty, self. window has value, so I'm [self. Window makekeyandvisible]; put to call application. Keywindow in front, incredibly shameful have value, real machine can also run, but do not know what reason, may be application life cycle about put, that friend know what reason to say ah, on such a inexplicable bug roughly fix.

OC Learning Path----Application.keyWindow.rootViewController and Self.window.rootViewController and [Self.window Makekeyandvisible]; Small discoveries

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.