在 UIViewController 中调用方法以定位错误

Call method in UIViewController to target error

在我的 MainMainViewController 中,我创建了新的 UIView (ContentView)。我设置

DetailViewController *detailView = 
   [[DetailViewController alloc] initWithObject:paAnnotation];
detailView.view.frame = CGRectMake(0, 
                                   0, 
                                   [self getWidthOfScreen], 
                                   [self getWidthOfScreen]);
[contentView addSubview:detailView.view];

它工作正常,但在我的 DetailViewController 中,我创建了 UIButton 并设置了目标操作。但是当我点击按钮时它崩溃并向我显示错误。你能告诉我问题出在哪里吗?

- (id)initWithObject:paAnnotation {

    if ((self = [super init])) {
        self.annotation = paAnnotation;
    }

    return self;
}    

- (void)viewDidAppear:(BOOL)animated {

        UIButton *closeButton = [[UIButton alloc] initWithFrame:CGRectMake(50, 50, 50, 50)];
        closeButton.backgroundColor = [UIColor redColor];
        [closeButton addTarget:self 
                        action:@selector(closeContent) 
              forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:closeButton];

}

- (void)closeContent {
    NSLog(@"Test");
}

错误:

-[GEOVectorTile closeContent]: unrecognized selector sent to instance 0x19d0a1e0

在您的 MainMainViewController 中,尝试在初始化时保留您的 detailView。或者在 MainMainViewController 中创建 detailView as retain 属性 然后使用它。