我的按钮被禁用,但我想在用户点击它时显示一个消息框。我该怎么做?另外我想提一下 UIbutton 是在 UITableview 上添加的,我尝试了下面的代码,但它总是else
在DisableClick()
起作用。
在 cellForRowAtIndexPath:
button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setFrame:CGRectMake(180, 6, 30, 30)];
[button setTag:4000];
[button addTarget:self action:@selector(click:event:) forControlEvents:UIControlEventTouchDown];
UITapGestureRecognizer* gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(DisableClick:)];
[self.view addGestureRecognizer:gesture];
[gesture release];
[cell.contentView addSubview:button];
在DisableClick()
- (void)DisableClick:(UIButton*)sender {
UITapGestureRecognizer *recognizer = (UITapGestureRecognizer *)sender;
CGPoint pt = [recognizer locationOfTouch:0 inView:market];
if (CGRectContainsPoint(market.bounds, pt)) {
NSLog(@"Disabled button tapped");
}
else
{
NSLog(@"go out"); // it's always go to here
}
}