I'm creating an iPhone app that shows a large number of pins on a map. I need the app to push another view that will show lots of information for that location, when the pin is tapped.
In my viewDidAppear i have a piece of code that sets the title and subtitle values of the pin just for test purposes.
-(void)viewDidAppear:(BOOL)animated
{
pin.title = #"Some title";
pin.subtitle = #"Some subtitle";
}
in my didSelectAnnotationView delegate i have something along this lines
- (void)mapView:(MKMapView *)mapView
didSelectAnnotationView:(MKAnnotationView *)view
{
[self performSegueWithIdentifier:#"showPinDetails" sender:self];
}
Now, when i tap on the pin, a popover appears for a brief moment, showing the title and subtitle in a popup, and then the segue pushes the details view. When I tap the back buton to retun me to the map view, the popup is still visible.
How can I somehow completely hide or disable the popup? If i don't set the title and subtitle values the didSelectAnnotationView delegate doesn't get called at all. I will gladly post additional code if you need me to, I just wanted to keep things as simple as I could.
Am I doing this wrong? Should I use some different method to achieve what I need to do? Thanks
You are not setting canShowCallout
canShowCallout -> A Boolean value indicating whether the annotation view is able to display extra information in a callout bubble.
Discussion ->
If the value of this property is YES, a standard callout bubble is shown when the user taps a selected annotation view
For More info you can visit MKAnnotationView Class Reference
Ok, I was stupid, when adding pins all i needed to do is to set the pin property canShowCallout:
annotationView.canShowCallout = NO;
Related
I have a question about the MKPinAnnotationView. First of all I entered coordinates of the pins and after that called the viewForAnnotation to build them and also add them the a right button.
But my question is how can I select different actions for those pins?
When I look for the button tag in NSLog, it always shows 0 for every pin so I can't make it with tags.
Here is the code of the button if it means something:
for (int i=0;i<=[[mapview annotations]count];i++) {
pinView.tag = i ;
rightButton.tag=i;
}
You don't need to (and should not) use tags.
Instead, in the action method, you can determine which annotation was selected and then execute different logic based on that.
You don't even need to create your own action method. When a callout button is tapped, the map view will call its calloutAccessoryControlTapped delegate method which gives you a reference to the annotation (ie. view.annotation). If you decide to use the delegate method, remove the addTarget from viewForAnnotation and just implement the delegate method.
If you want to use your own action method for some reason, you can determine which annotation was selected by looking at the map view's selectedAnnotations property. The selected annotation will be at index 0 (be sure to first check that the array's count is not zero).
For sample code of all the above, see this question:
How to keep data associated with MKAnnotation from being lost after a callout pops up and user taps disclosure button?
I want to add custom annotationView callout which contains
1. Title
2. subtitles
3. a button
The button can display on the right (rightCalloutAccessoryView) or left leftCalloutAccessoryViewsides of the callout. I want to add the button in the middle of the callout and under title->subtitle. How can I do?
There is no API for this. You could try not using the standard callout (canShowCallout = NO), catch the taps and drags on the AnnotationView manually and show your own UI by adding custom Views based on the position of the AnnotationView. This seems very fragile, though.
I have a checkin related app. When user clicks a venue on map, callout will popup and show its name and address. At the same time, if the venue is within 1000m from current location, a check in button will be displayed.
To a venue that can checkin, all I want is,
when callout is popup, check in button shows. when callout is disappear, that button disappears too.
Now show button works well, but I don't know how to detect callout visible status. Is there any callback method that callout show/hide?
Thanks in advance!
Callout appears when annotation is selected - you can use mapView:didSelectAnnotationView: method in delegate to track that event. Callout hides when annotation is deselected - use mapView:didDeselectAnnotationView: method to track that event.
As you can see here it is about selected property of MKAnnotationView, which is saying that If the property contains YES, the annotation view is displaying a callout bubble.
You may additionally implement an observer for this property, to implement your functionality.
I am writing an app where I need to show the thumbnail image on each of the table cell, when this thumbnail image is taped it should push new view with larger image. So there should be two touch events on single cell, one for image and other for showing detail view. By default in the didSelectRowAtIndexPath I am invoking detail view which is working fine.
Can someone suggest an approach please.
Thanks,
Bhaskar
The simplest way would be to add the thumbnail in a button as the accessory view of the cell. When the button was hit it would call accessory view method which would load the next view.
from your question, it is understood that you are having a custom cell with an uiimageview in it. In that case, wherever you tap in that cell, may be in the image or the empty portion, the didSelectRow atIndexPath method is invoked. The better way is to use a button to show any of them,, similar to a discloure button in navigators.
I would recommend TechZen's approach: You could add a custom UIButton and place it wherever you like in the cell, and that freedom is nice, but in my experience these tend to really kill scrolling performance. Whatever optimizations are done for accessory views may make them a better experience for your users than buttons.
I agree with Alex. More info: This is what the Detail Disclosure Button accessory view is for on table rows. For an example of this, see the Favorites tab in the Phone application. Tapping on a row calls the person, but tapping on that blue circular button to the right takes you to the detail view for the person's contact info. Another example is the YouTube application.
I think you want something like the YouTube application where tapping on the table cell displays a larger image, and tapping the detail disclosure button takes you to metadata about the image.
See the docs for UITableViewCell for how to add a detail disclosure button. It's very simple.
Since we know that the image is in a cell and I hate subclassing, we can put together a little fun hack. You can just use the cell.imageView property and toss a category on UIImageView:
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
if([self.superview isKindOfClass:[UITableViewCell class]]){
if([touches anyObject].tapCount == 1){
//Image was tapped, issue notification, we use the cell as the object
[[NSNotificationCenter defaultCenter] postNotificationName:#"CellImageTapped" object:self.superview]
//just return after the notification
return;
}
}
//if it wasn't a tap, just forward the touch
[super touchesEnded:touches withEvent:event];
}
Then in the table view controller, you can resolve the selected cell by:
NSIndexPath indexOfSelectedCellImage = [self.tableview indexPathForCell:[notificaton object]];
I didn't check, but the superview of the cell.imageView may be the contentView, in that case just substitute in the following:
…if([self.superview.superview isKindOfClass:[UITableViewCell class]])…
…[[NSNotificationCenter defaultCenter] postNotificationName:#"CellImageTapped" object:self.superview.superview]…
Note: Be sure to have your table view controller subscribe to the notification.
I have a mapview and i put an annotation which shows a custom title and subtitle pin.
When the mapview starts the pin is visible but the title and subtitle are not.
I have to press on the pin to show up the title and subtitle. Is it possible to show the title and subtitle without pressing the pin?
this is just a suggestion but you can try
[myCustomAnnotationView becomeFirstResponder];
you could use
MKMapView *mapView;
id<MKAnnotation> myAnnotation;
// initialize mapView and myAnnotation...
[mapView selectAnnotation:myAnnotation animated:YES]
http://www.iphonedevsdk.com/forum/iphone-sdk-development/19740-trigger-mkannotationview-callout-bubble.html#post110447
anyway guys seems to be a problem at xcode specific version check the above link. this is working