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

标签 ios objective-c uiviewcontroller uibutton addtarget

在我的 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/

相关文章:

ios - 无法从 plist 读取 CLLocationDegrees

ios - 使用未解析的标识符 'FlurryAdInterstitial'

ios - Objective-C 中的倾斜图像

ios - 渐变图层背景

ios - 在多个收藏 View 中显示电影列表的详细 View

ios - Cocoa Pods 未在应用程序内部更新

ios - BSD atos 在 Linux 上可用吗?

objective-c - 解析 CSV : how can NSScanner recognize empty field (i. e。 ,,)?

iphone - 使用页面控制?

ios5 - 带有 Storyboard的模态视图 Controller 的大小