0

I currently get the error "cannot find protocol declaration for changeMapTyp" and I have no idea why. I imported all the required files, but it hasn't solved my problem.

As mentioned in my comments, the error message disappears when I delete the #import MapsViewController.h in the MapsBackgroundViewController.h, but I can´t delete the line, because I need to write this lines

MapsViewController *myMapsViewController = [[MapsViewController alloc] init];
[self setDelegate:myMapsViewController];

to set my delegate. Am I right?

Here is my code:

MapsBackgroundViewcontroller.h

#import "MapsViewController.h"

@protocol ChangeMapTyp <NSObject>
@required
- (void)segmentedControllChangedMapType:(MKMapType) type ;
@end


@interface MapBackgroundViewController : UIViewController{
IBOutlet UISegmentedControl *segmentedControl;
MKMapType mapType;
id < ChangeMapTyp> delegate;

}


@property (nonatomic) IBOutlet UISegmentedControl *segmentedControl;

@property(nonatomic) MKMapType mapType;

@property(nonatomic)id delegate;

- (IBAction)segmentedControllChanged:(id)sender;

MapsBackgroundViewController.m

#import "MapBackgroundViewController.h"

@interface MapBackgroundViewController ()

@end

@implementation MapBackgroundViewController
@synthesize segmentedControl, mapType, delegate;


- (void)viewDidLoad
{
    [super viewDidLoad];

    // that´s why I can´t delete the import ???
    MapsViewController *myMapsViewController = [[MapsViewController alloc] init]; 
    [self setDelegate:myMapsViewController];    
 }


- (IBAction)segmentedControllChanged:(id)sender {

    if (segmentedControl.selectedSegmentIndex == 0) {
        mapType = MKMapTypeStandard;
    }else if (segmentedControl.selectedSegmentIndex == 1) {
        mapType = MKMapTypeSatellite;
    } else if (segmentedControl.selectedSegmentIndex == 2) {
     //   [self.delegate setMapType:MKMapTypeHybrid];
        mapType = MKMapTypeHybrid;
    }


    //Is anyone listening
    if([delegate respondsToSelector:@selector(segmentedControllChangedMapType:)])
    {
        //send the delegate function with the amount entered by the user
        [delegate segmentedControllChangedMapType:mapType];
    }  
    [self dismissModalViewControllerAnimated:YES];    
}

MapsViewController.h

#import "MapBackgroundViewController.h"

@class MapBackgroundViewController;

@interface MapsViewController : UIViewController<MKMapViewDelegate,
UISearchBarDelegate,   ChangeMapTyp >{        //here i get the error message
@private
IBOutlet MKMapView *map;

}

@property (nonatomic, retain) IBOutlet MKMapView *map;

@end

MapsViewController.m #import "MapBackgroundViewController.h"

@interface MapsViewController ()

@end

@implementation MapsViewController

@synthesize map;

- (void)segmentedControllChangedMapType: (MKMapType) type{
    map.mapType = type;   
}
Maksim
  • 2,054
  • 3
  • 17
  • 33
Kito
  • 1,375
  • 4
  • 17
  • 37

1 Answers1

2

In MapsViewController.h, you need to have -

#import "MapBackgroundViewController.h" //Keep This line

@class MapBackgroundViewController;   // Remove this line

@interface MapsViewController : UIViewController<MKMapViewDelegate,UISearchBarDelegate,   ChangeMapTyp >{     

Hope this will fix your issue.

rishi
  • 11,779
  • 4
  • 40
  • 59
  • unfortunately this doesn´t solve the problem. but as i mentioned, if i delete the import in MapBackgroundViewcontroller, the error is gone. I also don´t need to set my delegate in the MapBackgroundViewController anymore, because i already set it in the prepareforsegue (in MapsViewController) method like this: if ([segue.identifier isEqualToString: @"showMapBackground"]) { MapBackgroundViewController *myCtrl = segue.destinationViewController ; myCtrl.delegate = self; } so , problem solved. – Kito May 21 '12 at 07:47