1

私はいくつかの助けが必要です。今日は、セルにUIImageViewが含まれているテーブルビューのカスタムセルについて作業しています。 ImageViewでは、長いジェスチャーを実装したいと思います。私はこれを下に与えるためのコードを実装します。しかし、私は自分のコードで何か間違っている。このビューでは長いプレスで一度サイズが変更されますが、私は数秒後に削除することができますし、テーブルビューのセルに戻ってくる 誰でも私を提案できますか?テーブルビューのカスタムセルの画像上で長押しのジェスチャー

更新:

long gesture Image

ここでは、コードです!

- (void)celllongpressed:(UILongPressGestureRecognizer *)gesture 
{ 

if (gesture.state == UIGestureRecognizerStateBegan) 
{ 
    cell = (ActivityFeedCell *)[gesture view]; 
} 
if (gesture.state == UIGestureRecognizerStateChanged) 
{ 
    cell = (ActivityFeedCell *)[gesture view]; 
    logGes_view=[[UIView alloc]initWithFrame:CGRectMake(5, 0,self.view.frame.size.width-10,self.view.frame.size.height)]; 
    image=[[UIImageView alloc]initWithFrame:CGRectMake(0, 80,self.view.frame.size.width, self.view.frame.size.height-80)]; 
    image.image=cell.updated_imgView.image; 
    UILabel *name_label=[[UILabel alloc]initWithFrame:CGRectMake(10, 15, 150, 30)]; 
    //city_label.backgroundColor=[UIColor yellowColor]; 
    name_label.text=lgGesNamelbl; 
    UILabel *city_label=[[UILabel alloc]initWithFrame:CGRectMake(10, 50, 180, 30)]; 
    //city_label.backgroundColor=[UIColor yellowColor]; 
    city_label.text=lgGesCitylbl; 
    [logGes_view addSubview:city_label]; 
     [logGes_view addSubview:name_label]; 
    [logGes_view addSubview:image]; 
    logGes_view.backgroundColor=[UIColor whiteColor]; 
    [self.view addSubview:logGes_view]; 
} 
if (gesture.state == UIGestureRecognizerStateEnded) 
{ 
    // cell = (ActivityFeedCell *)[gesture view]; 
    [logGes_view removeFromSuperview]; 
} 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
UILongPressGestureRecognizer *gesture1 = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(celllongpressed:)]; 
[gesture1 setDelegate:self]; 
[gesture1 setMinimumPressDuration:1.0]; 
[ cell setUserInteractionEnabled:YES]; 
[cell addGestureRecognizer:gesture1]; 
} 
+0

同じ結果の出力とコードを表示します。 –

+0

clipSubviewsはCustomCellで確認できます!プロトタイプセルを使用している場合は、cellForRowAtIndexPath()またはInterface Builderで無効にしてください。 – Ariel

+0

アタッチ画像plz –

答えて

0
[cell addGestureRecognizer:gesture1] 

ライン

[ cell.yourimageview setUserInteractionEnabled:YES]; // This enable user interaction on the image view. Required!! 


[cell.yourimageview addGestureRecognizer:gesture1]; //yourimageview is your image outlet 
+0

私はすでにこれを試しています! –

+0

は、カスタムセルでクリップビューを有効にしていますか? – Ariel

+0

問題の長いプレスコードを追加してください。 –

1
 UILongPressGestureRecognizer *reconizer=[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(handleLongPress:)]; 
        [reconizer setMinimumPressDuration:1.0]; 
       [cell addGestureRecognizer:reconizer]; 


-(void)handleLongPress:(UILongPressGestureRecognizer*)reconizer 
{ 
if (gesture.state == UIGestureRecognizerStateBegan) 
{ 
    UITableViewCell *cell = (UITableViewCell *)[gesture view]; 
    NSIndexPath *indexPath = [tableview indexPathForCell:cell]; 
    NSString *s = [NSString stringWithFormat: @"row=%1ld",(long)indexPath.row]; 
    [self setTitle: s]; 
} 
if (gesture.state == UIGestureRecognizerStateChanged) 
{ 
cell = (UITableViewCell *)[gesture view]; 
    cell.updated_imgView.frame=CGRectMake(0, 0, tableview.frame.size.width, tableview.frame.size.height); 
     } 
if (gesture.state == UIGestureRecognizerStateEnded) 
{ 
cell = (UITableViewCell *)[gesture view]; 
    cell.updated_imgView.frame=CGRectMake(0, 0, 100, 100); 
} 

}

-(BOOL)canBecomeFirstResponder 
{ 
    return YES; 
} 
+0

このコードを試してみましたか?@simerkaur –

+0

は動作していますか? @imerkaur –

+0

あなたはクラッシュメッセージを送ってください。@simerkaur –

0

それを試してみてください以下に置き換え: セルは、それがクロスセルではないでしょうサイズ変更にそうImageViewののスーパーですフレーム サイズ変更後にmainViewに追加します。

+0

!私のアプリがクラッシュする –

+0

例外メッセージ – jagdish

+0

を提供してください。これは、クラスがメソッドに応答しない場合に発生します。呼び出す前に、if([ActivityFeedViewController instancesRespondToSelector:@selector(celllongpressed:)]){ / } – jagdish

関連する問題