For my iPad app, I am programmatically creating several UIImage views that I display on the screen. The code looks basically like this:
for(ModelObject *model in ModelsList){ //create a UIImage view from the model object UIImageView *icon = [[UIImageView alloc] initWithFrame:model.icon_frame]; icon.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:model.icon_path ofType:@"png"]]; //add the imageview to a mutable array to keep track of them [myImageViews addObject:icon]; // add the view as a subview [self.view addSubview:icon]; }
So now I have a bunch of icons displayed on the screen. But I would like to intercept touch events from the UIImageViews
that I created programmatically, so that it calls some other method, preferably with an argument containing the sender's id or some other distinguishing information that I can use to determine which UIImageView
was touched.
What is the best practices way of accomplishing this?
I am new to iOS so recommended reading would also be greatly appreciated.