Use block as a proxy for value transfer
Here http://www.cnblogs.com/iCocos/p/4659878.html, the author has the agent, Block, notification of the value of the way summed up a bit, today's use is not the same, What we're using here is to save a block code in one way, and then go back inside the Blcok to execute it.
- Here is used in the map,,,, well don't say much, open dry
1: First, define a Blcok
void (^resultblock) (Cllocation *currentloc, Clplacemark *placemark, NSString *error);
2. Declare a method with block blocks to make it easier to call outside and pass in block code blocks
1 /* * 2 * get current position 3 *4 * @param block to get the current position after processing block5 */6 -(void) Getcurrentlocation: (resultblock) block;
3. Define a Blcok attribute in the implementation file, which records the block passed in the following method, and executes
// stores the code blocks passed by the outside world @property (nonatomic, copy) Resultblock Resultblock;
4. How to implement block correspondence
1 //Get Current Location2- (void) Getcurrentlocation: (resultblock) block3 {4 //Record code block5Self.resultblock =Block;6 7 8 //determine whether to turn on location services9 if([Cllocationmanager locationservicesenabled]) {Ten //Start updating user locations One [Self.locationm startupdatinglocation]; A } - Else - { theSelf.resultblock (nil, nil,@"location service is not turned on"); - } -}
5. Determine where code blocks need to be executed and execute the external incoming block (as in the article mentioned above)
if (self.resultblock) { self.resultblock ([Locations lastobject], [Placemarks Firstobject], nil); }
6, outside the use of the time directly with the use of UIView animation, in the back will attach a blcok, we just need to implement the corresponding code in this blcok, the system will automatically save the code first, and then put in the blcok inside to execute
1 [[Icocoslocationtool Sharedicocoslocationtool] getcurrentlocation:^ (cllocation *currentloc, CLPlacemark *placemark, NSString *error) {2 if0) {3 NSLog (@ " %@ ---- %@", Currentloc, placemark.name); 4 }5 }];
iOS Development--Project Practical Technology OC Chapter & use block as a proxy for value transfer