2012-05-20 68 views
0

我目前收到錯誤「找不到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; 
} 
+0

終於我修好了。我只需要刪除MapsBackgroundViewController.h中的#import MapViewController.h行。 – Kito

+0

但現在我沒有任何錯誤消息,但我的mapType不會按預期更改。任何人都是ieda? – Kito

+0

現在是什麼問題,你能更新你的問題嗎? – rishi

回答

2

MapsViewController.h,你需要有 -

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

@class MapBackgroundViewController; // Remove this line 

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

希望這將解決您的問題。

+0

不幸的是,這並不能解決問題。但正如我所提到的,如果我刪除MapBackgroundViewcontroller中的導入,錯誤消失了。 我也不需要在MapBackgroundViewController中設置我的委託,因爲我已經將它設置在像這樣的prepareforsegue(在MapsViewController)方法中: if([segue.identifier isEqualToString:@「showMapBackground」]){ MapBackgroundViewController * myCtrl = segue.destinationViewController; myCtrl.delegate = self; } 這樣,問題就解決了。 – Kito

相關問題