English 中文(简体)
我正在制订守则,以找到用户所在地,并 st忙。
原标题:I am working on the codes to get location of user and get stuck

First please take a look at codes below

CoreLocationController.h
#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>

@protocol CoreLocationControllerDelegate     // Line 1
@required                       

- (void)locationUpdate:(CLLocation *)location;
- (void)locationError:(NSError *)error;

@end

/* Declare class named CoreLocationControll and inherited from CLLocationManagerDelegate */
@interface CoreLocationController : NSObject <CLLocationManagerDelegate> {
    CLLocationManager *locMgr;
    id delegate;
}

@property (nonatomic, retain) CLLocationManager *locMgr;            // claim setter and getter for locMgr
@property (nonatomic, assign) id delegate;                          // claim setter and getter for delegate

@end


CoreLcationController.m
#import "CoreLocationController.h"

@implementation CoreLocationController
@synthesize locMgr, delegate;

/* Is triggered by - (void)startUpdatingLocation from CoreLocationDemoViewController.m*/
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
    NSLog(@"CORE_LOCATION_CONTROLLER=======>DID_UPDATE_TO_LOCATION");
    if([self.delegate conformsToProtocol:@protocol(CoreLocationControllerDelegate)]) // line 2
        [self.delegate locationUpdate:newLocation];

}

My questions are what line 1 and line 2 do and why I looked up CoreLocationControllerDelegate but no reference on it

问题回答

你们要求的是客观议定书宣言。 该守则正在宣布一项名为“核心”的协议。 简言之,议定书是一份方法清单,如果某一物体符合议定书,即可预期予以执行。

For example, the UITextFieldDelegate protocol contains the various methods that an object should or must implement if it wants to be the delegate for a text field.

第1行<代码>@required是指该物体必须采用下列方法以符合议定书。 如果你宣布你的反对符合议定书,它必须执行这些方法,或者你会犯错误(或警告,我可以记住这些错误)。

Line 2 is a safety check to make sure that the delegate conforms to the protocol (in this case, that it implements the required methods) before the delegate methods are called. This prevents a runtime crash where an unrecognised selector is sent to the object.





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签