iPhone:MKAnnotation 中的循环导入警告:未找到方法
我刚刚通过使用类转发解决了循环依赖问题。现在,我收到一条警告,提示未找到“showSumDetails”方法。我根本不明白为什么会发生这种情况,任何帮助将不胜感激。这里包括一些代码:
MyAnnotation.h
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
//#import "MyMapViewController.h" obviously this wasn't possible :-(
@class MyMapViewController;
@interface MyAnnotation : NSObject<MKAnnotation> {
MyMapViewController* mapController;
}
MyMapViewController.h
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import <MapKit/MKReverseGeocoder.h>
#import "MyAnnotation.h"
@interface MyMapViewController : UIViewController <MKMapViewDelegate>{
MyAnnotation *annot;
}
MyMapViewController.m - 该方法实际存在的位置,并且也在头文件中定义。
@implementation MyMapViewController
@synthesize annot;
-(void) showSumDetails:(id)aSumData{
NSLog(@"mapViewController-showSumDetails");
SumDetailsViewController *wrController = [[SumDetailsViewController alloc] init];
wrController.sumData = aSumData;
[self.navigationController pushViewController:wrController animated:YES];//This needs to be pushed
[wrController release];
}
@end
但是 MyAnnotation.m 中的以下方法找不到上面的方法:-(
@implementation MyAnnotation
@synthesize sumData;
@synthesize mapController;
- (void) showPD{//is also defined in header file
NSLog(@"sPD - MyAnn");
[mapController showSumDetails:sumData]; //This doesn't have a clue about showSumDetails method- Why??
}
我很乐意提供更多信息。请帮忙!!!
I just resolved a cyclic dependency problem by using class forwarding. Now, I am getting a warning of no 'showSumDetails' method found. I don't understand why it should happen at all, any help will be appreciated. Including a bit of code here:
MyAnnotation.h
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
//#import "MyMapViewController.h" obviously this wasn't possible :-(
@class MyMapViewController;
@interface MyAnnotation : NSObject<MKAnnotation> {
MyMapViewController* mapController;
}
MyMapViewController.h
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import <MapKit/MKReverseGeocoder.h>
#import "MyAnnotation.h"
@interface MyMapViewController : UIViewController <MKMapViewDelegate>{
MyAnnotation *annot;
}
MyMapViewController.m - where the method actually exists, and it is defined in the header file as well.
@implementation MyMapViewController
@synthesize annot;
-(void) showSumDetails:(id)aSumData{
NSLog(@"mapViewController-showSumDetails");
SumDetailsViewController *wrController = [[SumDetailsViewController alloc] init];
wrController.sumData = aSumData;
[self.navigationController pushViewController:wrController animated:YES];//This needs to be pushed
[wrController release];
}
@end
But the following method in MyAnnotation.m can't find the method above :-(
@implementation MyAnnotation
@synthesize sumData;
@synthesize mapController;
- (void) showPD{//is also defined in header file
NSLog(@"sPD - MyAnn");
[mapController showSumDetails:sumData]; //This doesn't have a clue about showSumDetails method- Why??
}
I'd be glad to provide any more info. Please help!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否在 MyAnnotation.m 中导入了 MyMapViewController.h ?
由于您在 MyAnnotation.h 中使用 MyMapViewController 的前向引用,因此您需要在 MyAnnotation.m 中导入 MyMapViewController.h。
Did you import MyMapViewController.h in MyAnnotation.m?
Since you're using a forward reference for MyMapViewController in MyAnnotation.h you need to import MyMapViewController.h in MyAnnotation.m.