iOS Development---pass-through encyclopedia

Source: Internet
Author: User
Tags notification center

Notification/proxy/block can be passed value

(All can be passed down)

The simplest and most straightforward pass-through property values

Two-reverse transmission with block more concise

Three notification value usage scenarios
1-Many controllers need to know an event that should be notified (the process of passing a parameter is a pass value);
2-transfer values between two controllers separated by a multilayer

———————————————————————————————————————————————————————————
8 Ways of transmitting values
(Very comprehensive, do not know who tidied up, first thank you. Take it all together to learn)

? Define initialization methods in the UI, all the same is used in one interface to push the other side of the world, in short you have to think that since the custom initialization method, at least to be able to create the object in the current method. So this method is not suitable for callbacks.

1. Define the initialization method, use the content you want to pass as a parameter, and set multiple parameters if you need to pass more than one.

2 Go in the right place? Call? Define initialization method.



Proxy transfer value: (Shun Chuan pass all the line)

1> the agreement (the name is generally xxxdelegate), the parameters of the law in the agreement depend on what you want to deliver.

2> Setting agent properties (again, using assign anti-loop reference)

3> in need of adjustment, this step is more abstract, as the above example, we need to click on the button when the

4> Pass the value and cancel the interface, so our delegate is on the right side of this? call

5> let the corresponding object become the agent,? Like to specify a proxy at the time of creation?

6> adhere to the Protocol, implement the appropriate method, and then do the logical processing in the method



Single-Pass value: (Shun Chuan Chuan) The advantage of a single case is that as long as it is created once, the rest of the time access to the object is the same, so many times? Some information is stored in a singleton, so there is no need to enter the value of the row, only need to create a single example to



Attribute value: (Shun Chuan)
1 need to define public properties
2 need an object that you need to pass a value to
3 Assigning values to properties



Notification Pass value: (Shun Chuan pass all the line)
The value of the third interface is passed to the first interface.
1. In the first interface, a notification center, through the notification, register a listener event
2. In the first sector, set up an event to receive notifications.
3. In the dealloc of the first sector, remove the notification centre
4. In the third interface, build a notification hub, send notifications via notification hubs (the process of sending notifications is the process of passing values, passing the value of the transfer as the value of the object to the first interface



Appdelegate Pass Value:
Declare in Appdelegate? A property
Save Properties via Appdelegate *appdelegate = [[[UIApplication Sharedapplication] delegate] appdelegate *app = [UIApplication Shared Application].delegate Using Attributes



Block Pass value: (Go backward and pass) block is also used for callbacks.

1 aliases The block and writes the arguments that need to be passed in the parameter list as formal parameters

2 Setting the Block property (note using copy)

3 Set the current block of the law

4 Tune in the right place? Similar to Agent

5 Make a block polygon call where the object is created



Nsuserdefault or the value of the piece: (Shun Chuan pass all the line)

[[Nsuserdefaults Standarduserdefaults] Objectforkey:]

Initialize value: (Shun Chuan:)

The inverted pass needs to be in "Viewdidappear" "Viewwillappear".

iOS Development---pass-through encyclopedia

Related Article

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.