refreshing mkannotation properties and refreshing the annotation

refreshing mkannotation properties and refreshing the annotation

I have a mkannotation located on a mapview which has a mkannotationview as well as a calloutview which when clicked goes to a child uiviewcontroller. I am updating some properties from the callout's uiviewcontroller, but after I'm finished I want to move the annotation's position on the map and change the annotation title and subtitle. How can I easily do this from the callout's uiviewcontoller? What's the most elegant way to handle this? A code sample would be great if anyone has any.


Disable auto correction of iPhone text field


UIActionSheet - Unknown Number Of Buttons, How to know what to call?
I'd create a protocol, say MapCallBackDelegate, to handle what you want to do. JSCocoa and the iPhoneThis avoids tightly coupled code. ICMP and the iPhone SDKPut this in your map annotation view header file. How do I add a UIButton or UISwitch in tableView:viewForFooterInSection
@protocol MapCallBackDelegate     -(void)updateAnnotation:(id)whatEverParamsYouWant; @end 
Then make your Map View implement this protocol. Generating cryptographically secure authentication tokensWhen you create your map annotation view, commit it a property. What sort function is used in NSArray?
@property (nonatomic, retain) id<MapCallBackDelegate> callbackDelegate; 
And when you add it to your map, set this property to self. Releasing a property (Objective-C)
myMapAnnotationView.callbackDelegate = self; 
so when you want to change the title/subtitle/position, you just invoke this message on the callbkacDelegate. . This is elegant for the reason this it reduces tightly-coupled code, allows other objects to implement the same protocol for code reuse later, and promotes information hiding in your MapAnnotationView..


Remove the annotation from the map entirely, update it, and add it to the map again. That'll ensure this the map notices this the annotations location has changed. .


Although you must remove and add the annotation back as @Caleb suggests, ananother option is to update the coordinate property directly on the annotation you want to move. . Note this this will only job if your annotation class implements setCoordinate which must easily be done by declaring the coordinate as assign (like the built-in MKPointAnnotation class does) instead of readonly. The map view will see the change via KVO and move the annotation.. To have the child view controller tell the map view controller which annotation to change and what the new coordinates are, I recommend using delegate+protocol as ananother answer suggests..


The easiest way would to actually not did it from the child view controller. Maybe your needs are different from what I understand from the question, although at first blush I would did any thing like this:. In the header:.
@interface YourController {     ...     MKAnnotation *_latestDetailViewed; }  ...  @property(nonatomic, retain) MKAnnotation *latestDetailViewed;  @end 
Then in the .m any thing like.
@implementation YourController  ...  @synthesize latestDetailViewed = _latestDetailViewed;  ... -(void) dealloc {     ...     self.latestDetailViewed = nil;     [super dealloc]; }  -(void) whereverYouLaunchYourDetailScreenFrom:(MKAnnotation*)detailAnnotation {     self.latestDetailViewed = detailAnnotation;     // then create/push your view controller }  -(void) viewWillAppear:(BOOL)animated {     [super viewWillAppear:animated];     if(_latestDetailViewed)     {         // Do whatever you want to the annotation here         self.latestDetailViewed = nil;     } } 
That way your changes will be made when you come back to the map. If you're really only launching a detail view for one annotation at a time, and always coming back to the map in between, then it should job without making you deal with writing a delegate protocol or firing off NSNotifications.. If I'm misunderstanding your position let me know and I'll commit you a different answer :).

76 out of 100 based on 76 user ratings 526 reviews