1

在我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
4

1 回答 1

2

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

于 2015-06-29T07:51:30.370 回答