在我的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创建为保留属性,然后使用它。

关于ios - 调用UIViewController中的方法以解决错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31110223/

10-10 20:52