2

現在、私は単純な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];
}
4

2 に答える 2

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

    if(CGRectContainsPoint(yourButton.frame, tapLocation))
    {
      [self showPerLessonOptions];
    }
}
于 2012-07-09T08:14:45.060 に答える