The sci-fi usage of appdelegate

Source: Internet
Author: User

Learning is always a gradual process, at the beginning of the time to know less, when encountering a demand will be racked up to think how to achieve, and as the study continues to deepen, understand more and more, encounter a demand when there will be more than one instant to solve the copy, the problem is to choose a best solution copy. It seems to be far away, or to talk about the appdelegate that has not been studied.
Said not studied also is not right, like the application's starting process, each agent execution order, registers pushes the event to obtain the push information, opens the URL what, has studied repeatedly, this time to say the sci-fi usage mainly refers to: "Delegate". Just suddenly a sense of open-minded and hair. Start here:

Appdelegate *_sysdege = [[UIApplication sharedapplication] delegate];

Here the _sysdege point to a system proxy pointer, and is built in each app, can be called at any time Yo, with him has the following conveniences:
1. You can easily get the Uinavigationcontroller
Write application write more, for the later view switch convenient, often use the structure based on Uinavigationcontroller. Later wrote more and more sci-fi, in the view based on Uinavigationcontroller, Addsubview, the result add view to continue to push, this time has no uinavigationcontroller how to do it. Well, I used to put the global variable directly, did not expect this is can be directly taken, embarrassing a ~
2. You can directly use the variables declared by appdelegate
Get an already initialized class, inside the variable can also be called directly, back to the previous different view of the variable transfer topic, what is the method?

Declare a delegate for the second class;
In addition, a single case is implemented;
notification via message;
Through the exchange of documents;
Through Nsuserdefaults;
through global variables;
binding through variables;
through Block;

E, OK, I remember the previous discussion of the value of the problem, I only know three ways, now casually say eight kinds of, and add today to say this is nine kinds of, another one ~
3. Call some global functions
Many times, we a method, not only in this class to use, that class also to use, in order to achieve convenient invocation and unified management, we will be many times to write a class in a single case, of course, this time in the management still have some confusion: some functions are common, put in which application can be used; Some functions are only used by this app. So now you know how to separate these functions?
OK, the above usage is very convenient ha, but always can not be called every time, all write a variable out of it, very long very urgy, definitely to customize a macro:

#define SYSDEGE (Appdelegate *) [[uiapplication Sharedapplication] delegate]

In this way, when you want to use the direct sysdege.xxx is good. You're still struggling with this macro. Do you want each file to be defined? Pro, haven't you seen the sci-fi usage of-prefix.pch files? Hurry up and get your lessons.

reprint Please specify: transfer from Rainbird's personal blog
This article links: The sci-fi usage of appdelegate


Appdelegate's sci-fi usage

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.