我将imgaes放置如下。
在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");
}
显示图像列。触摸事件仅适用于第一张图像。如何触发所有图像的触摸事件。请提供解决方案。
答案 0 :(得分:0)
尝试使用UI按钮并将图像添加到按钮的图像属性,而不是使用imageView。 yoU可以通过简单的方式识别点击。 使用按钮的tag属性可以识别单击了哪个按钮。
UIButton *imageButton1;
imageButton1.tag=buttonIdentifier;
[imageButton1 addTarget:self action:@selector(imageSelected:) forControlEvents:UIControlEventTouchUpInside];