Moe Moe - 2 years ago 67
iOS Question

Store additional associated infomation in a UIView

I've been reading up a lot about Gesture Recognizers on SO - and have managed to write a working code which when a long-press is recognised on an UIImage, an action sheet appears:

{ ...
UILongPressGestureRecognizer *longPressWall = [[[UILongPressGestureRecognizer alloc]
initWithTarget:self action:@selector(deleteImage:)] autorelease];
longPressWall.minimumPressDuration = 0.4;
[l addGestureRecognizer:longPressWall];
... }

-(void)deleteImage:(UILongPressGestureRecognizer*)sender {
if(UIGestureRecognizerStateBegan == sender.state) {
UIActionSheet *as = [[UIActionSheet alloc] initWithTitle:@"" delegate:self cancelButtonTitle:@"Close" destructiveButtonTitle:@"Delete Screenshot" otherButtonTitles: nil];
[as showInView:masterView];
[as release];

So, sending information to the Selector
is a little tricky in this situation.
I want to send a HTTP request to a server when deleteImage is called, so I need some information from the view.

Is there anyway to store information into the
and retrieve it from
(for example) ?


Answer Source

The obvious way is to use the tag property. If you need more info you can always subclass the UIImageView and add an extra property.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download