目前我正在使用简单的 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];
}