在我的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");
}
ERROR:
-[GEOVectorTile closeContent]: unrecognized selector sent to instance 0x19d0a1e0
答案 0 :(得分:2)
在MainMainViewController中,尝试在初始化时保留detailView。或者在MainMainViewController中将detailView创建为retain属性,然后使用它。