Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

teranceTT

macrumors newbie
Original poster
Feb 23, 2014
2
0
Hello,

I have two UI Map Views. The user selects the location from the first one and the selected location is passed to the second ui map view (where it is displayed). In order to store the selected location, I have created primitive singleton class (I am at the beginning process of studying the iOS programming).

However, the selected location doesn't appear at the second UI View Map controller. Would you be so kind to tell where is my mistake? Here is the link to the github: https://github.com/terancet/Projects_GeoChat
 
Post your relevant code here. It's unlikely someone will download your github work and wade through it trying to figure out what your issue is. Use the CODE tag to wrap you code.
 
Class where I store information about the selected place:

Code:
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
@interface GeoChatInformationAboutTheSelectedPlace : NSObject <MKMapViewDelegate>
//create object that mimic the Place with the required information
@property (nonatomic)         NSUInteger numberOfThePostsForTheSelectedLocation;
@property (nonatomic, strong) MKPointAnnotation *annotation;
+(GeoChatInformationAboutTheSelectedPlace *)returnInstance;
@end


[B]//implementation of the above class[/B]
#import "GeoChatInformationAboutTheSelectedPlace.h"

@implementation GeoChatInformationAboutTheSelectedPlace
static GeoChatInformationAboutTheSelectedPlace *info=NULL;
+(GeoChatInformationAboutTheSelectedPlace *)returnInstance{
    if (!info){
        info = [[GeoChatInformationAboutTheSelectedPlace alloc] init];
        info.annotation=[[MKPointAnnotation alloc] init];
    }
    return info;
}
@end

How I add the selected location:
Code:
.h
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import "GeoChatInformationAboutTheSelectedPlace.h"
@interface GeoChatMapViewController : UIViewController <MKMapViewDelegate>
@property (weak, nonatomic) IBOutlet MKMapView *map;
@property (strong,nonatomic) NSMutableArray *matchingItems;
@property (strong, nonatomic) IBOutlet UITextField *textSearch;
@property (strong, nonatomic) GeoChatInformationAboutTheSelectedPlace *info;
@property (weak, nonatomic) IBOutlet UIStepper *stepper;
- (IBAction)increaseDecreaseRadiousOfTheSearch:(id)sender;
@end

[B]/*------------part of the implementation class--------*/[/B]
//selecting the location and displaying its coordinates
-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Would you like to add this location?"
                                                    message:[view.annotation title]
                                                   delegate:self
                                          cancelButtonTitle:@"Yep!"
                                          otherButtonTitles:@"No :(", nil];
    [alert show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex==0) {
        MKAnnotationView *selectedAnnotation=[_map.selectedAnnotations objectAtIndex:0];
        
        if ([selectedAnnotation isKindOfClass:[MKPointAnnotation class]]) {
            MKPointAnnotation *pa = (MKPointAnnotation *)selectedAnnotation;
            //[_info.arrayOfTheSelectedPlaces addObject:pa];
            _info.annotation=pa;
        }
    }
}
- (void)viewDidLoad {
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    _info=[GeoChatInformationAboutTheSelectedPlace returnInstance];
    _map.showsUserLocation=YES;
}

How I display the selected annotation at the second map

Code:
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import "GeoChatInformationAboutTheSelectedPlace.h"
@interface GeoChatProjectSavedLocationToDisplayOnMapViewController : UIViewController <MKMapViewDelegate>
@property (strong, nonatomic) IBOutlet MKMapView *map;
@property (strong, nonatomic) GeoChatInformationAboutTheSelectedPlace *info;
@property (strong, nonatomic) MKPointAnnotation *bb;
@end

[B]/*----------------------------.m---------------------------------------*/[/B]
#import "GeoChatProjectSavedLocationToDisplayOnMapViewController.h"

@interface GeoChatProjectSavedLocationToDisplayOnMapViewController ()
@end

@implementation GeoChatProjectSavedLocationToDisplayOnMapViewController
-(void)setBb:(MKPointAnnotation *)bb{
    _bb=bb;
}
-(void)setMap:(MKMapView *)map {
    _map=map;
    _map.delegate=self;
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    _map.showsUserLocation=YES;
    _info=[GeoChatInformationAboutTheSelectedPlace returnInstance];

[B]    //displays nothing[/B]
    NSLog(@"%@",[_info.annotation title]);
[B]    //however, when I write 
    //NSLog(@"%@",_info.annotation);
    //It displays me that the object is not nill
    //adds nothing to the map[/B]
    [_map addAnnotation:_info.annotation];
}
@end
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.