在UIView中存储其他相关信息 [英] Store additional associated infomation in a UIView
问题描述
我一直在阅读很多关于SO的手势识别器 - 并设法编写了一个工作代码,当在UIImage上识别出长按时,会出现一个操作表:
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.userInteractionEnabled=YES;
[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];
}
}
因此,向选择器发送信息 deleteImage:
在这种情况下有点棘手。
我想在调用deleteImage时向服务器发送HTTP请求,所以我需要从视图中获取一些信息。
So, sending information to the Selector deleteImage:
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.
无论如何将信息存储到 UIImageView
并从 sender.view.myinfo
(例如)中检索它?
Is there anyway to store information into the UIImageView
and retrieve it from sender.view.myinfo
(for example) ?
谢谢!
推荐答案
显而易见的方法是使用tag属性。如果您需要更多信息,您可以随时继承UIImageView并添加额外的属性。
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.
这篇关于在UIView中存储其他相关信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!