【问题标题】:No visible @interface for selector选择器没有可见的@interface
【发布时间】:2014-07-27 22:22:14
【问题描述】:

基本上我知道通常会出问题的地方(与我声明的方法不同),但看看这个。当然我可能会遗漏一些东西,但我已经尝试解决这个问题一个小时。我也打扫过了。

错误:DetailGymViewController.m:46:62:“CustomAnnotation”没有可见的@interface 声明选择器“initWithCoordinate:title:subtitle:”

错误代码:

#import "DetailGymViewController.h"
#import "CustomAnnotation.h"

@interface DetailGymViewController ()

@end

@implementation DetailGymViewController {
    CLLocationManager *locationManager;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    locationManager = [[CLLocationManager alloc] init];
    self.mapView.delegate = self;



    self.nameLabel.text = self.name;
    self.longitudeLabel.text = [NSString stringWithFormat:(@"%f"), self.longitude];
    self.latitudeLabel.text = [NSString stringWithFormat:(@"%f"), self.latitude];
}

#pragma mark - Map/Locations delegates

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
    NSLog(@"Failed to get location with error: %@", error);
}

- (void)mapViewDidFinishLoadingMap:(MKMapView *)mapView
{
    CLLocationCoordinate2D coordinate;
    coordinate.latitude = self.latitude;
    coordinate.longitude = self.longitude;
    // ERROR HERE
    CustomAnnotation *annotation = [[CustomAnnotation alloc] initWithCoordinate:coordinate title:self.name subtitle:@"Info"];
    [self.mapView addAnnotation:(id)annotation];
}

CustomAnnotation.h 的声明:

#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>

@interface CustomAnnotation : NSObject

@property (strong, nonatomic) NSString *title;
@property (strong, nonatomic) NSString *subtitle;
@property (nonatomic,assign) CLLocationCoordinate2D coordinate;

- (id)initWithCoordinate:(CLLocationCoordinate2D)coordinate title:(NSString *)title subtitle:(NSString *)subtitle;

@end

还有,我的 CustomAnnotation.m 文件:

        #import "CustomAnnotation.h"

        @implementation CustomAnnotation

        -(id) initWithCoordinate:(CLLocationCoordinate2D)coordinate title:(NSString *)title subtitle:(NSString *)subtitle {
            if ((self = [super init])) {
                self.coordinate = coordinate;
                self.title = title;
                self.subtitle = subtitle;
            }
            return self;
        }

        @end

【问题讨论】:

  • 您能否检查一下您是否错过了将 CustomAnnotation 添加到应用程序目标?
  • @ldindu 在哪里可以找到?奇怪的是我在另一个文件中使用了提到的 init 方法,我没有收到任何错误
  • 你的initWithCoordinate方法在哪里?
  • 好的,这意味着它们被添加到正确的目标上,那么可能还有其他问题。
  • @andrewbuilder 在我的 CustomAnnotation.h 文件中,它在我的帖子中。

标签: ios objective-c initialization declaration


【解决方案1】:

我真的不知道哪里出了问题。我只是错误地点击了 cmd + n 并且错误消失了。 我不知道 Xcode 做了什么。

【讨论】:

  • 您当然意识到,使用 Cmd+N 会导致您所知道的生命瞬间停止,并且您体内的每个分子都以光速爆炸。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-10-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-07-27
  • 2021-09-22
相关资源
最近更新 更多