我目前收到錯誤「找不到changeMapTyp的協議聲明」,我不知道爲什麼。我導入了所有必需的文件,但它沒有解決我的問題。找不到changeMapTyp的協議聲明iOS
正如我在評論中提到,當我刪除MapsBackgroundViewController.h
的#import MapsViewController.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
MapsViewContro ller.m #進口 「MapBackgroundViewController.h」
@interface MapsViewController()
@end
@implementation MapsViewController
@synthesize map;
- (void)segmentedControllChangedMapType: (MKMapType) type{
map.mapType = type;
}
終於我修好了。我只需要刪除MapsBackgroundViewController.h中的#import MapViewController.h行。 – Kito
但現在我沒有任何錯誤消息,但我的mapType不會按預期更改。任何人都是ieda? – Kito
現在是什麼問題,你能更新你的問題嗎? – rishi