【发布时间】:2014-03-07 14:46:20
【问题描述】:
我想在我的自定义标题类中添加点击事件。 以下是我的代码。当我单击标题区域时,它会给出 EXC_BAD_ACCESS。
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
UITapGestureRecognizer *singleFingerTap =
[[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(handleSingleTap:)];
[self.view addGestureRecognizer:singleFingerTap];
}
return self;
}
- (void)handleSingleTap:(UITapGestureRecognizer *)recognizer {
CGPoint location = [recognizer locationInView:[recognizer.view superview]];
//Do stuff here...
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
【问题讨论】:
-
尝试在
viewDidLoad中进行分配代码。超后 -
获取 [_UIScrollViewAutomaticContentSizeConstraint handleSingleTap:]:在 viewdidload 中发送到实例 0x8c70800 时无法识别的选择器
标签: ios objective-c exc-bad-access