Objective c 如何更改ViewDidLoad中注释的标题?

Objective c 如何更改ViewDidLoad中注释的标题?,objective-c,xcode,mkannotation,Objective C,Xcode,Mkannotation,我有mkannotation的代码,但我不知道如何在ViewDidLoad中更改标题 这是我的代码: LocationView.h ... @interface AddressAnnotation : NSObject<MKAnnotation> { CLLocationCoordinate2D coordinate; NSString *mTitle; NSString *mSubTitle; } @end @interface LocationVi

我有mkannotation的代码,但我不知道如何在ViewDidLoad中更改标题

这是我的代码:

LocationView.h

...
@interface AddressAnnotation : NSObject<MKAnnotation> {
    CLLocationCoordinate2D coordinate;

    NSString *mTitle;
    NSString *mSubTitle;

}

@end

@interface LocationView : UIViewController<MKMapViewDelegate> {

    IBOutlet MKMapView *mapView;

    AddressAnnotation *addAnnotation;

}

@property (nonatomic, retain) Offers *offer;

@property (retain, nonatomic) IBOutlet MKMapView *mapView;


-(CLLocationCoordinate2D) addressLocation;


@end
。。。
@接口地址注释:NSObject{
CLLocationCoordinate2D坐标;
NSString*mTitle;
NSString*mSubTitle;
}
@结束
@接口位置视图:UIViewController{
IBMKMAPVIEW*mapView;
AddressAnnotation*addAnnotation;
}
@不动产(非原子,保留)报价*报价;
@属性(保留,非原子)IBMOutlet MKMapView*mapView;
-(CLLocationCoordinate2D)地址位置;
@结束
LocationView.m

#import "LocationView.h"

@implementation AddressAnnotation

@synthesize coordinate;

- (NSString *)subtitle{
    return @"Sub Title";
}
- (NSString *)title{
    return @"Title";
}

-(id)initWithCoordinate:(CLLocationCoordinate2D) c{
    coordinate=c;
    //NSLog(@"%f,%f",c.latitude,c.longitude);
    return self;
}

@end

@interface LocationView ()

@end

@implementation LocationView

@synthesize mapView, offer;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    // I want in this method to change title

    MKCoordinateRegion region;
    MKCoordinateSpan span;
    span.latitudeDelta=0.2;
    span.longitudeDelta=0.2;

    CLLocationCoordinate2D location = [self addressLocation];
    region.span=span;
    region.center=location;

    if(addAnnotation != nil) {
        [mapView removeAnnotation:addAnnotation];
        addAnnotation = nil;
    }

    addAnnotation = [[AddressAnnotation alloc] initWithCoordinate:location];

    [mapView addAnnotation:addAnnotation];

    [mapView setRegion:region animated:TRUE];
    [mapView regionThatFits:region];


    //[mapView selectAnnotation:mLodgeAnnotation animated:YES];


}


- (void)viewDidUnload
{
    [super viewDidUnload];


}

//:(MKMapView *)mapView

-(CLLocationCoordinate2D) addressLocation {


    double latitude = 0.0;
    double longitude = 0.0;

    if(offer.lat > 0 && offer.lon > 0) {
        latitude = [offer.lat doubleValue];
        longitude = [offer.lon doubleValue];
    }


    CLLocationCoordinate2D location;
    location.latitude = latitude;
    location.longitude = longitude;

    return location;
}

- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation{
    MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentloc"];

    annView.pinColor = MKPinAnnotationColorGreen;
    annView.animatesDrop=TRUE;
    annView.canShowCallout = YES;
    annView.calloutOffset = CGPointMake(-5, 5);

    return annView;
}


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
#导入“LocationView.h”
@实现地址注释
@综合坐标;
-(NSString*)副标题{
返回@“子标题”;
}
-(NSString*)标题{
返回@“标题”;
}
-(id)initWithCoordinate:(CLLocationCoordinate2D)c{
坐标=c;
//NSLog(@“%f,%f”,c.纬度,c.经度);
回归自我;
}
@结束
@接口位置视图()
@结束
@实现位置视图
@综合地图视图,提供;
-(id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil
{
self=[super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
如果(自我){
//自定义初始化
}
回归自我;
}
-(无效)viewDidLoad
{
[超级视图下载];
//我想在这个方法中更改标题
协调区域;
Mk坐标跨度;
span.latitudeDelta=0.2;
span.longitudeDelta=0.2;
CLLocationCoordinate2D位置=[自寻址位置];
地区span=span;
区域。中心=位置;
if(addAnnotation!=nil){
[mapView removeAnnotation:addAnnotation];
addAnnotation=nil;
}
addAnnotation=[[AddressAnnotation alloc]initWithCoordinate:location];
[地图视图添加注释:添加注释];
[地图视图设置区域:区域动画:真];
[地图视图区域匹配:区域];
//[mapView selectAnnotation:mLodgeAnnotation动画:是];
}
-(无效)视图卸载
{
[超级视频下载];
}
//:(MKMapView*)mapView
-(CLLocationCoordinate2D)地址位置{
双纬度=0.0;
双经度=0.0;
如果(offer.lat>0&&offer.lon>0){
纬度=[offer.lat doubleValue];
经度=[offer.lon doubleValue];
}
CLLOCATION坐标2D定位;
位置。纬度=纬度;
location.longitude=经度;
返回位置;
}
-(MKAnnotationView*)地图视图:(MKMapView*)地图视图注释:(id)注释{
MKPinAnnotationView*annView=[[MKPinAnnotationView alloc]initWithAnnotation:annotation重用标识符:@“currentloc”];
annView.pinColor=MKPinAnnotationColorGreen;
annView.animatesDrop=TRUE;
annView.canShowCallout=是;
annView.calloutOffset=CGPointMake(-5,5);
返回视图;
}
-(布尔)应自动旋转指针面定向:(UIInterfaceOrientation)interfaceOrientation
{
返回(interfaceOrientation==UIInterfaceOrientationGraphic);
}
@结束

为什么不简单地综合AddressAnnotation类的属性,并使用类似

addAnnotation.mTitle = yourNewString;
我是否误解了你的问题?到目前为止,这似乎太明显了

编辑

当然,你必须把这个还给我。例如:

- (NSString *)title{ return mTitle;}

是的,现在可以用了。对不起,我是新来的。c:)谢谢你的帮助,没问题。如果你仔细想想,这是合乎逻辑的。你的LocationView如何知道你在另一节课上对私人iVar做了什么。你必须告诉我;-)对我越来越了解objective-c逻辑。