Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing SQL data from Annotation click to a new view
    primarykey
    data
    text
    <p>I have tried to find an answer online and maybe there is an answer out there but I'm struggling to find it.</p> <p>The Concept - I have data downloaded from an SQL. I collect this data and an array displays the annotations on the map. When the annotation is clicked the correct title and subtitle are shown. When the button on the annotation is clicked a new View pops up display data relevant to that co-ordinate.</p> <p>The Problem - In this data that I download from an SQL there is other data apart from title, co-ordinates etc that I want passed to this other view, such as images, details, price, website details etc. I can do this without problems through a table view (the index:row method), but for the life of me, not in a Map View.</p> <p>So my question is - how can I collect the information that the annotations pick up and pass this through to the other view along with the other data. I tried adding the extra data in an array with the annotations and produce this when the user clicks the button, but only the last object shows in the array.</p> <p>I know there is some serious learning I need to get my head around for arrays and passing data about; but any help will be much appreciated.</p> <p>My Hotspot class:</p> <pre><code> @interface Hotspot : NSObject &lt;MKAnnotation&gt; { CLLocationCoordinate2D coordinate; NSString *title; NSString *subTitle; NSString *detail; float price; NSString *contact; } @property (nonatomic, assign) CLLocationCoordinate2D coordinate; @property (nonatomic, copy) NSString *title; @property (nonatomic, copy) NSString *subTitle; @property (nonatomic, copy) NSString *detail; @property (nonatomic) float price; @property (nonatomic, copy) NSString *contact; </code></pre> <p>My MapView (Company class holds the data I got from the SQL file - I load all the data up in ViewDidLoad using 'companys' and then use an array (this works okay):-</p> <pre><code>- (void)loadAnnotations { NSMutableArray *annotations = [[NSMutableArray alloc] init]; for (int i = 0; i &lt; [companys count]; i++) // storedNumber = i; { Company* company = [self.companys objectAtIndex:i]; CGFloat latitude = company.latitude; CGFloat longitude = company.longitude; Hotspot *myAnnotations = [[Hotspot alloc] init]; MKCoordinateRegion region = { { latitude , longitude } , { 12.0f , 12.0f } }; [myAnnotations setCoordinate: region.center]; [myAnnotations setSubTitle:company.type]; [myAnnotations setTitle:company.name]; [myAnnotations setDetail:company.details]; [myAnnotations setPrice:company.price]; [myAnnotations setContact:company.contact]; [annotations addObject: myAnnotations]; } [promoView addAnnotations: annotations]; </code></pre> <p>My Annotation View (this will need to change once I've added your suggestion:</p> <pre><code>- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id &lt;MKAnnotation&gt;)annotation { NSLog(@"AnnotationView"); // if it's the user location, just return nil. if ([annotation isKindOfClass:[MKUserLocation class]]) return nil; // static NSString *AnnotationViewID = @"annotationViewID"; MKPinAnnotationView* pinView = (MKPinAnnotationView*)[promoView dequeueReusableAnnotationViewWithIdentifier:@"CustomPinAnnotationView"]; if (!pinView) { pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"CustomPinAnnotation"] autorelease]; UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; NSLog(@"Map View Title, %@", annotation.title); [rightButton setTitle:annotation.title forState:UIControlStateNormal]; [rightButton addTarget:self action:@selector(showDetails:) forControlEvents:UIControlEventTouchUpInside]; pinView.rightCalloutAccessoryView = rightButton; UIImageView *profileIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"profile.png"]]; pinView.leftCalloutAccessoryView = profileIconView; [profileIconView release]; if ([annotation isKindOfClass:[Hotspot class]]) { pinView.pinColor = MKPinAnnotationColorRed; pinView.draggable =YES; } else pinView.pinColor = MKPinAnnotationColorGreen; pinView.animatesDrop = YES; pinView.canShowCallout = YES; } else pinView.annotation = annotation; return pinView; } </code></pre> <p>Your code - </p> <pre><code>- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control { PromoViewController *promoController = [[PromoViewController alloc] initWithNibName:@"DetailView" bundle:nil]; promoController.hotspot = (Hotspot*)view.annotation; [self.navigationController pushViewController:promoController animated:YES]; [promoController release]; </code></pre> <p>For the PromoViewController, I've set the .h file like this:</p> <pre><code>@interface PromoViewController : UIViewController { IBOutlet UILabel *nameLabel; IBOutlet UILabel *detailLabel; IBOutlet UILabel *typeLabel; IBOutlet UILabel *contactLabel; IBOutlet UILabel *priceLabel; } </code></pre> <p>But I'm not 100% sure how to implement it and also I do get an error with this line:-</p> <pre><code>promoController.hotspot = (Hotspot*)view.annotation; </code></pre> <p>Saying that the property hotspot is not found on object PromoViewController.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload