全部,
尝试确定如何在搜索时在注释图钉标题中显示用户搜索位置的名称,而不是让它们预先确定,这很容易。用户输入位置的搜索栏的当前代码如下:
- (IBAction) showAddress
{
[addressField resignFirstResponder];
CLLocationCoordinate2D location = [self addressLocation];
MKCoordinateRegion region;
MKCoordinateSpan span;
span.latitudeDelta=0.2;
span.longitudeDelta=0.2;
region.span=span;
region.center=location;
[mapView setRegion:region animated:TRUE];
[mapView regionThatFits:region];
MapViewAnnotation *addAnnotation = [[MapViewAnnotation alloc] initWithTitle:@"" andCoordinate:location];
[self.mapView addAnnotation:addAnnotation];
}
我在下面声明了我的头衔信息:
@implementation AddressAnnotation
@synthesize _name;
-(id)initWithName:(NSString*)name address:(NSString*)address coordinate:(CLLocationCoordinate2D)coordinate {
if ((self = [super init]))
{
_name = [name copy];
}
return self;
}
-(NSString *)title
{
if ([_name isKindOfClass:[NSNull class]])
return @"Unknown charge";
else
return _name;
}
@end
我的理解是我需要将我的 initWithTitle 替换为标题变量名称,但我的问题是它会是什么样子,这足以显示用户这些自定义搜索的标题吗?
谢谢!!格雷格