3

私には2つの問題があり、完全に混乱しています。私を助けてください

1)サブビューの内側にある画像ビューにクリックリスナーを割り当てたいという1つの問題に直面し、そのサブビューはのセルにありUITableViewます。

私のテーブルビューセルには、クリックリスナーを提供したい2つのイメージビューがあり、どのイメージビューがどの行でクリックされたかなどを識別します。

私が書いたscrollview.userinteractionEnable=YES;場合、私didSelectRowAtIndexPathは応答しません。私はそれがサブビューのせいであることを知っています。しかし、変更するscrollview.userinteractionEnable=NO;と、didselectrowatIndexpathコードが実行されます。しかし、スクロールビューは水平にスクロールしません..

私は何をしますか ?両方のImageViewで水平スクロールとImage-viewクリックリスナーが必要です。

** scrollview サブクラスを作成してクリックの問題を解決**

これは私のカスタムセルクラスです

cellScrollViewClass *scrollView = [[cellScrollViewClass alloc] initWithFrame:CGRectMake(0.0,0.0,430,187)];
     scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * 3,scrollView.frame.size.height);
    scrollView.scrollEnabled=YES;
    scrollView.userInteractionEnabled=YES;

    for (int i = 0; i < 3; i++) {
        CGRect frame;
        frame.origin.x = scrollView.frame.size.width * i;
        frame.origin.y = 0;
        frame.size = scrollView.frame.size;

        if(i==2) // to check Last item must be train Engine   
        {
            UIView *EngineView = [[UIView alloc]initWithFrame:frame];
            UIImageView *engineImageView = [[UIImageView alloc]initWithFrame:CGRectMake(-112.5, 6, 430, 180)];
            UIImage *Image = [UIImage imageNamed:@"backengine.png"];
            engineImageView.contentMode = UIViewContentModeScaleAspectFit;
            engineImageView.image = Image;
            [EngineView addSubview:engineImageView];
            [scrollView addSubview:EngineView];  // add 3rd imageview that is Train Engine to end of scrollview
        }
        else{ // Not equal to 2 than it must be wagon of train. 

    UIView *wagon = [[UIView alloc]initWithFrame:frame];
    UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"wagon.png"]];
    wagon.backgroundColor = background;

    UIView *videoviewContainer = [[UIView alloc]initWithFrame:CGRectMake(20, 40, 220 , 200)];

    UIImageView *videoImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0,0, 220, 100)];
    UIImage *bgImage = [UIImage imageNamed:@"video.png"];
    videoImageView.image = bgImage;
    videoviewContainer.contentMode = UIViewContentModeLeft; // set Video Image view to left hand side of wagon UIView
            videoImageView.tag=2;


    [videoviewContainer addSubview:videoImageView];

    UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTapGestureCaptured:)];
    [videoImageView addGestureRecognizer:singleTap];
    [videoImageView setMultipleTouchEnabled:YES];
    [videoImageView setUserInteractionEnabled:YES];

    UIView *textUiView = [[UIView alloc]initWithFrame:CGRectMake(238,28, 150 , 187)];
    textUiView.contentMode = UIViewContentModeRight;
    UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(28,10, 150 , 87)];
    label.text=@"This is testing text for IOS app to check line are aligned or not and to check video image and nested views for UIviews";
    label.backgroundColor = [UIColor clearColor];
    label.textColor=[UIColor redColor];
    label.numberOfLines = 4;
    [textUiView addSubview:label];

    [wagon addSubview:textUiView];
    [wagon addSubview:videoviewContainer];
    [scrollView addSubview:wagon];
    [self.contentView addSubview:scrollView];
  }
  }
  }
    return self;
  }


  - (void)singleTapGestureCaptured:(UITapGestureRecognizer *)gesture
    {

     NSLog(@"Touch event on view %d",gesture.view.tag);
     }

そして、このようなScrollviewサブクラスを作成しました..

@implementation cellScrollViewClass
  - (id)initWithFrame:(CGRect)frame
    {
  self = [super initWithFrame:frame];
   if (self) {
    // Initialization code
    NSLog(@"You are in scrollview");
        }
   return self;
     }

これは正しい実装方法ですか?

ここに画像の説明を入力

どんな助けでも大歓迎です。前もって感謝します。

4

5 に答える 5

1

を使用しUITapGestureRecognizerます。タップ ジェスチャ レコグナイザーを作成し、作成時に各イメージ ビューにアタッチします。また、作成時に画像ビューのタグを設定して、セル上にあるものを識別できるようにします。

認識エンジンからコールバックを取得すると、次の方法でタグを取得できます。

recogniser.view.tag

また、テーブル ビュー セル クラスが見つかるまでスーパービューをループすることで、テーブル ビュー セルを取得できます。

UIView *superView = recogniser.view.superview;
while (superView != nil && ![superView isKindOfClass:[UITableViewCell class]]) {
    superView = superView.superview;
}

次に、使用してテーブル ビューからインデックス パスを取得できます。

[tableView indexPathForCell:superView];
于 2013-04-25T09:00:17.377 に答える
0

イメージビューの同じフレームでイメージビューにカスタムボタンを追加でき、ボタンにセレクターを追加できます。

于 2013-04-25T12:05:54.243 に答える
0

オンクリックリスナーを取得するにUIImageViewは、そのカテゴリを取得し、touches begin methodコールバックを使用して「tableViewController」に委任します。

タグを使用して、クリックされた画像と行を識別します。

重複を避けるために、セルが既に割り当てられている場合は、以前の画像を削除してelse条件を設定します。

于 2013-04-25T08:57:08.400 に答える
0

UIScrollViewデリゲートコールバックを実装し、ユーザーが行っているスクロールの種類(水平スクロールまたは垂直スクロール)を確認してから、テーブルビューまたはスクロールビューオフセットを手動で変更する必要があります。これがほとんど唯一の方法です...

画像については、everyImage に UIButton を設定し、それらをセレクターにリンクする必要があります。その後、ボタンのタグを使用して、それがどの画像であったかを知ることができます。

于 2013-04-25T09:17:41.083 に答える