0

以下のように画像を配置します。

ListView.m 内

-(void)viewDidLoad()
 {
        int j=5;
        for (int i=0; i<[po_id_array count]; i++) {

                ViewForTickImage *tickimage=[[ViewForTickImage alloc]initWithFrame:CGRectMake(5, j, 35, 35)];

                NSLog(@"----------%d",j);
                j=j+17;
                [tickimage setTick:FALSE];
                [tickimage setTag:i];
               // [tickimage setDelegate:self];
                [self.view addSubview:tickimage];

            }

        }

ViewForTickImage.h ファイルのコードは次のとおりです。

@interface ViewForTickImage : UIView
{
    BOOL ticked;
    NSMutableArray *list_selected;
    id delegate;
    UIImageView *currentImg;
    AppDelegate *appdelegate;

}
//@property(nonatomic,readwrite)BOOL ticked;
@property(nonatomic,readwrite,getter=isTicked,setter=setTick:)BOOL ticked;
@property(nonatomic,retain) UIImageView *currentImg;
-(void)checkTickVisiblilityForListAllView;

ViewForTickImage.m ファイルのコードは次のとおりです::

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {

        currentImg = [[UIImageView alloc]initWithFrame:frame];
        [currentImg setContentMode:UIViewContentModeScaleAspectFit];
        UIImage *img=[UIImage imageNamed:@"image_unselect.png"];
        [currentImg setImage:img];
        [self addSubview:currentImg];
    }
    return self;
}

    -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

   NSLog(@"image selected");

}

画像の列を表示します。最初の画像だけタッチイベントが働きます。すべての画像に対してタッチイベントを発生させる方法を教えてください。解決策を教えてください。

4

1 に答える 1

0

imageView を使用する代わりに、UIbutton を使用して、ボタンのイメージ プロパティにイメージを追加してみてください。簡単な方法でクリックを識別できます。ボタンの tag プロパティを使用して、どのボタンがクリックされたかを識別できます。

   UIButton *imageButton1;
   imageButton1.tag=buttonIdentifier;
   [imageButton1 addTarget:self action:@selector(imageSelected:) forControlEvents:UIControlEventTouchUpInside];
于 2013-01-29T05:36:09.063 に答える