gpt4 book ai didi

iphone - 当我触摸tableview内部的按钮时,它会自动转到TabGesture方法,但是我想要按钮触摸方法?

转载 作者:行者123 更新时间:2023-12-01 16:56:27 25 4
gpt4 key购买 nike

目前,我正在使用简单的iPhone应用程序,使用UITableview输入Emp_Name,Emp_Salary等字段,并使用UIButton设置复选框等图像并设置目标并执行选择器,
当我触摸复选框按钮时,它会自动进入UITabGesture方法,但不会进入按钮触摸方法内部。如何解决这个问题,请帮帮我

我尝试了源代码:

- (void)viewDidLoad
{
[super viewDidLoad];
UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
[recognizer setNumberOfTouchesRequired:1];
recognizer.cancelsTouchesInView = NO;
[[self view] addGestureRecognizer:recognizer];
[recognizer release];
}

-(void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer // TabGesture method
{
NSLog(@"Tab received.");
}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;


if (indexPath.section == 0 && indexPath.row == 0)
{


perlessonCheckButton = [UIButton buttonWithType:UIButtonTypeCustom];
perlessonCheckButton.frame = CGRectMake(5, 5, 30, 30);
[perlessonCheckButton setImage:[UIImage imageNamed:@"tickAltered1.png"] forState:UIControlStateNormal];
[perlessonCheckButton addTarget:self action:@selector(showPerLessonOptions) forControlEvents:UIControlEventTouchUpInside];
[perlessonCheckButton setBackgroundColor:[UIColor lightTextColor]];
[perlessonCheckButton setUserInteractionEnabled:NO];
[cell.contentView addSubview:perlessonCheckButton];

}
}



-(void) showPerLessonOptions // Button method
{
[perlessonCheckButton setUserInteractionEnabled:NO];
[flatFeeCheckButton setUserInteractionEnabled:YES];

[perlessonCheckButton setImage:[UIImage imageNamed:@"tickAltered1.png"] forState:UIControlStateNormal];
[flatFeeCheckButton setImage:[UIImage imageNamed:@"untickAltered1.png"] forState:UIControlStateNormal];
}

最佳答案

-(void)handleSingleTap:(UIGestureRecognizer *)gestureRecognizer
{
CGPoint tapLocation = [gestureRecognizer locationInView:self.view];

if(CGRectContainsPoint(yourButton.frame, tapLocation))
{
[self showPerLessonOptions];
}
}

关于iphone - 当我触摸tableview内部的按钮时,它会自动转到TabGesture方法,但是我想要按钮触摸方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11391224/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com