<span id="Label3"></p>one, Datacenter Single-case Transmission value<p><p>Objective: to modify the background color of interface 1 by using a Single-pass value</p></p><p><p>second, the characteristics of single-case transmission: each change and get is the same value, used for information sharing between multiple interfaces, equivalent to the C language of global Variables. Single-instance participation is usually named after the start of the shared \ Default. A more detailed example of the usage and considerations of the single case will be approached in the subsequent Multi-line.</p></p><p><p>third, the realization of the Single-pass value:</p></p><p><p>1. Preparation Steps</p></p><p><p>1.1. Create a new project</p></p><p><p>1.2. Create a new class detacenter, which is inherited by NSObject</p></p><p><p>2, Single Example implementation</p></p><p><p>2.1. A singleton method (typically a class METHOD) is disclosed in the DetaCenter.h file, and a member variable of the Uicolor type is declared to store the value of the background color (which declares its own type as required by the actual requirement), because Uicolor is in the Uikit class, all of which are to be import <UIKit.UIKit.h> header File</p></p><p><p>The detailed code is as Follows:</p></p><p><p></p></p><p><p><span style="line-height: 1.5;">Implementing a singleton method in the 2.2detacenter.m file (creating a Singleton)</span></p></p><p><p>Declare a piece of datacenter memory space in the heap</p></p><p><p>Features: not automatically recycled, statically modified, static</p></p><p><p>The code is as Follows:</p></p><p><p></p></p><p><p></p></p><p><p></p></p><p><p><span style="line-height: 1.5;">The 2.3viewcontroller.m file contains the DetaCenter.h header file, and the Singleton is assigned and retrieved</span></p></p><p><p>The code is as Follows:</p></p><p><p></p></p><p><p><span style="font-size: 2em; line-height: 1.5;">second, the notification value</span></p></p><p><p>I. Purpose: modify the background color of interface 1 using notification value</p></p><p><p>second, the notification of the characteristics of the Value: multiple VC registration notification, a single VC send a notification, the registration notification of the VC response method (one-to-many value-added Mode)</p></p><p><p>three, simple steps: (first listen, then Send)</p></p><p><p>Interface 1 Registration Notice:</p></p><p><p>Add to notification hubs, using: delivery notification (nsnotification) itself to the method [[nsnotificationcenterdefaultcenter]addobserver:selfselector: @selector ( notimethod:) name:@ "changecolornoti" object:nil];</p></p><p><p>Interface 2 Send Notifications:</p></p><p><p>Use the Post method to respond with the same name notification [[nsnotificationcenterdefaultcenter]postnotificationname:@ ' Changecolornoti ' object:[ uicolorblackcolor] userinfo:nil];</p></p><p><p>Iv. Detailed Code</p></p><p><p>Interface 1. m file</p></p><p><p></p></p><p><p></p></p><p><p><span style="line-height: 1.5;">Interface 2. m file</span></p></p><p><p><span style="line-height: 1.5;"></span></p></p><p><p><span style="font-size: 2em; line-height: 1.5;">third, the Protocol proxy value</span></p></p><p><p>Objective: to modify the background color of interface 1 by using protocol proxy value</p></p><p><p>second, the characteristics of the value of the protocol agent: for example, modify the background color, you can set a special proxy class to implement, and other needs to modify the background color of all classes can sign a protocol to modify their own background color-the idea of encapsulation</p></p><p><p>third, step:</p></p><p><p>3.1 in Interface 2 (protocol proxy Class) formulates the protocol and declares the protocol method, but does not implement, who complies with the agreement who implements</p></p><p><p>3.2 in Interface 2 (protocol proxy class) exposes an ID pointer that carries the protocol</p></p><p><p>The code is as Follows:</p></p><p><p></p></p><p><p></p></p><p><p>3.3 in Interface 1 (compliance protocol Class) declaration Interface 2 (declaring the protocol Class) header file, and abide by the protocol</p></p><p><p>3.4 Association of protocols in interface 1 (adherence to protocol classes)</p></p><p><p>3.5 Implementing protocol methods in interface 1 (adherence to protocol classes)</p></p><p><p>The code is as Follows:</p></p><p><p></p></p><p><p></p></p><p><p></p></p><p><p></p></p><p><p></p></p><p><p><span style="line-height: 1.5;">3.6 Call the Protocol method in a state of the. m (protocol proxy Class) in interface 2, passing in parameters</span></p></p><p><p>The code is as Follows:</p></p><p><p></p></p><p><p></p></p><p><p><span style="font-size: 1.5em; line-height: 1.5;">Iv. Value of the block</span></p></p><p><p>I. Purpose: modify the background color of interface 1 using block pass value</p></p><p><p>second, the characteristics of the block transmission value: block transfer value is a piece of code to be executed area, to activate the code block area is to be executed, The block value is now Apple's official recommendation, but also a trend in the future</p></p><p><p>third, the step: I do not understand the block, do not do a long description to avoid misleading everyone, to be understood in the future, in the back to the knowledge points, here directly affixed to the Code.</p></p><p><p>Vc:</p></p><p><p></p></p><p><p></p></p><p><p></p></p><p><p>SVC.h</p></p><p><p></p></p><p><p></p></p><p><p>Svc.m</p></p><p><p></p></p><p><p></p></p><p><p></p></p><p><p>iOS Pass Value</p></p></span>
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