0

我目前收到错误“找不到 changeMapTyp 的协议声明”,我不知道为什么。我导入了所有必需的文件,但它并没有解决我的问题。

正如我在评论中提到的,当我删除#import MapsViewController.h中的 时,错误消息消失了MapsBackgroundViewController.h,但我不能删除该行,因为我需要写这行

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

设置我的代表。我对吗?

这是我的代码:

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;   
}
4

1 回答 1

2

MapsViewController.h中,您需要 -

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

@class MapBackgroundViewController;   // Remove this line

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

希望这能解决您的问题。

于 2012-05-20T16:17:00.143 回答