2012-04-18 68 views
2

私のビューに1つのUITableViewがあります。私のUITableViewの名前はtblTask​​です。
私はビューのx座標とy座標を取得するためにtouchesBeganメソッドを使用しています。
X座標とY座標を取得する

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    UITouch *touch = [touches anyObject]; 
    CGPoint location = [touch locationInView:self.view]; 

    NSLog(@"point........ %f .. %f",location.x,location.y); 



} 

しかし、私はtbltaskからtouchイベントを開始します。 tbltaskがメインビューのサブビューであっても、location.xとlocation.yは返されません。

私もテーブルのスクロールビューを無効にしようとしましたが、何も起こりません。これを設定すると

tbltask.userInteractionEnabled=NO; 

そして、それは座標与えるだろうが、私はtbltask相互作用が有効になっている場合でも、ビューの座標たいです。

+1

おそらく最も簡単な方法は、 'UITableView'をサブクラス化し、' touchesBeganオーバーライドするために、次のようになります '、' touchesMoved: 'と' touchesEnded: 'メソッドを。 '[super ...]'と同等のものを忘れずに呼んでください。 –

+1

okが試行します。それからあなたに知らせてください。 – KDeogharkar

+1

ここであなたが望むものを明確にすることができますか?あなたのビューのx、y、またはあなたのタッチのx、y?あなたのコードはあなたのタッチのx、yを返します。 – SomaMan

答えて

4
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    UITouch *touch ; 
    touch = [[event allTouches] anyObject]; 
    if ([touch view] == self.view){ 
     CGPoint location = [touch locationInView:touch.view]; 
     NSLog(@"point........ %f .. %f",location.x,location.y); 
     } 
} 
関連する問題