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 并将图像添加到按钮的图像属性。您可以通过简单的方式识别点击。使用按钮的标签属性,您可以识别单击了哪个按钮。

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