我如下放置图像。
在 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");
}
它显示图像列。触摸事件仅适用于第一张图像。如何为所有图像触发触摸事件。请给出解决方案。