如何重置标题/字幕调整后泡沫标注 [英] How to resize callout bubble after resetting title/subtitle

查看:179
本文介绍了如何重置标题/字幕调整后泡沫标注的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个MKAnnotation名图钉其中有一个标题和副标题。我希望能够动态地改变的标题在稍后的时间。我很接近,所以我宁愿没有做一个全新的AnnotationView,但如果我有我想那也没关系。我的问题是,一旦我更改标题文本,窗口不调整,并根据标题原本有多大,一些文本可能会被切断。

1)有没有我可以触发再次调整标注气泡窗口的事件?

2)另外,我检查,以确保该注释实际上首先有一个标题之前,我去重置冠军,但我遇到了一些麻烦铸造它,我检查后,有人可以帮我这个?我还是新的Objective-C和这个人与我搞砸了一段时间。


 #进口<基金会/ Foundation.h>
#进口< MapKit / MKAnnotation.h>@interface图钉:NSObject的< MKAnnotation> {
 CLLocationCoordinate2D _coordinate;
 * NSString的_title;
 * NSString的_subtitle;
 * NSString的_ID;
}@属性(非原子,只读)CLLocationCoordinate2D协调;
@属性(非原子,保留)的NSString *称号;
@属性(非原子,保留)的NSString *字幕;
@属性(非原子,保留)的NSString * ID; - (ID)initWithCoordinateAndInformation:(CLLocationCoordinate2D)坐标标题:(* NSString的)标题字幕:(* NSString的)字幕;@结束


   - (空)的MapView:(*的MKMapView)的MapView didSelectAnnotationView:(MKAnnotationView *)查看
{
 的NSLog(@注解被窃听!); 如果([view.annotation isKindOfClass:[图钉类]){
  view.annotation.title = @测试;          //警告这里,这可能无法实现...
          //但它是这个类的类型,我该如何将它转换为正确的类型?
 }}


解决方案

仍然有一些问题,但越来越近,也许。我想这一点,但仍没有运气。我部分在code从图纸的http://digdog.tumblr.com/post/252784277/mapkit-annotation-drag-and-drop-with-callout-info

   - (空)的MapView:(*的MKMapView)的MapView didSelectAnnotationView:(MKAnnotationView *)查看
{
    的NSLog(@注解被窃听!);    如果([view.annotation isKindOfClass:[图钉类]){
        ((图钉*)view.annotation).title伪= @测试;
    }    [个体经营willChangeValueForKey:@字幕]; //解决方法SDK 3.0,否则标注的信息将不会更新。
    [个体经营didChangeValueForKey:@字幕]; //解决方法SDK 3.0,否则标注的信息将不会更新。    [NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:@MKAnnotationCalloutInfoDidChangeNotification对象:个体经营]];
}

好消息是,我想通了,我的铸造问题,其他人谁可能是好奇。

 ((图钉*)view.annotation).title伪= @测试;

I created an MKAnnotation name PushPin which has a title and subtitle. I want to be able to dynamically change the title at a later time. I'm close so I'd rather not have to make a whole new AnnotationView, but if I have to I guess that's ok too. My problem is that, once I change the text for the title, the window does not resize and some text might get cut off depending on how big the title originally was.

1) Is there an event I can trigger to resize the callout bubble window again?

2) Also, I check to make sure that the annotation actually has a title first before I go resetting the title, but I had some trouble casting it after I checked, can someone help me out with this? I'm still new to objective-c and this one messed with me for a while.


#import <Foundation/Foundation.h>
#import <MapKit/MKAnnotation.h>

@interface PushPin : NSObject <MKAnnotation> {
 CLLocationCoordinate2D _coordinate;
 NSString *_title;
 NSString *_subtitle;
 NSString *_ID;
}

@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
@property (nonatomic, retain) NSString *title;
@property (nonatomic, retain) NSString *subtitle;
@property (nonatomic, retain) NSString *ID;

- (id) initWithCoordinateAndInformation:(CLLocationCoordinate2D)coordinate title:(NSString *)title subtitle:(NSString *)subtitle;

@end


- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
 NSLog(@"Annotation was TAPPED!");

 if ([view.annotation isKindOfClass:[PushPin class]]) {
  view.annotation.title = @"test";  

          // warning here, that this might not be implemented...
          // but it is for this class type, how do I cast it to the correct type?
 }

}

解决方案

Still having some problems, but getting closer maybe. I tried this, but still no luck. I am partially drawing on the code from http://digdog.tumblr.com/post/252784277/mapkit-annotation-drag-and-drop-with-callout-info

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
    NSLog(@"Annotation was TAPPED!");

    if ([view.annotation isKindOfClass:[PushPin class]]) {
        ((PushPin *)view.annotation).title = @"test";
    }

    [self willChangeValueForKey:@"subtitle"]; // Workaround for SDK 3.0, otherwise callout info won't update.
    [self didChangeValueForKey:@"subtitle"]; // Workaround for SDK 3.0, otherwise callout info won't update.

    [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:@"MKAnnotationCalloutInfoDidChangeNotification" object:self]];
}

Good news is that, I figured out my casting problem, for others who may be curious.

((PushPin *)view.annotation).title = @"test";

这篇关于如何重置标题/字幕调整后泡沫标注的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆