0

uitableviewの行のどちら側がクリックされたかを区別することは可能ですか?

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
  //which side of row has been detected left or right
}
4

2 に答える 2

7

UITableViewCellをサブクラス化できます。サブクラスでは、iVarを作成できますwasTouchOnLeft。次に、以下の例をオーバーライドtouchesBeganするか、次のようにします。touchesEnded

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
    UITouch *touch=(UITouch *)[touches anyObject];
    if([touch locationInView:self].x< (0.5 * self.frame.size.width) )
    {
        NSLog(@"Touched Left");
        wasTouchOnLeft=YES;
    }
    else {
        NSLog(@"Touched Right");
        wasTouchOnLeft=NO;
    }
    [super touchesEnded:touches withEvent:event];
}

ので、セルの変数にアクセスできますdidSelectRowAtIndexPathUITableViewControllerwasTouchOnLeft

于 2012-08-23T09:19:36.077 に答える
1

この方法でこれを直接決定することはできません。ただし、この機能が本当に必要な場合は、2つの大きなボタン(左側に1つ、右側に1つ)を持つカスタムテーブルビューセルを作成するか、セルにタッチ認識機能を適用します。

これを持っている場合は、アクションをコントローラーに委任します(セルに保存して、経由でアクセスすることもできます)

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
  if(((YourCustomTableCell*)[tableView cellForRowAtIndexPath:indexPath]).clickedSideProperty) action;
else anotherAction;
}

ただし、didSelectRowからアクセスするよりも、テーブルセルから委任する方が適切です…</ p>

于 2012-08-23T09:16:40.957 に答える