Rak*_*eva 3 ios uitapgesturerecognizer
我的问题类似于这个问题,唯一的例外是 - 我的ImageView出现在窗口内的同一个地方,里面有不同的内容.内容具有唯一标识符,我想用它来调用特定于内容的操作.
为了快速回顾一下,这家伙正在寻找一种方法将参数传递给initWithTarget方法的selector部分.
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:itemSKU:)];
Run Code Online (Sandbox Code Playgroud)
如何将属性传递给handleTapGesture方法,或者如何读取唯一值?
任何想法都赞赏.
编辑:内容从数据库中提取,每次都不同.唯一标识符非常类似于SSN - 不再重复.
您可以UIImageView使用内容标识符设置tag属性,然后从选择器中读取该信息.
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)];
[imageView addGestureRecognizer:tapGesture];
imageView.tag = 0;
Run Code Online (Sandbox Code Playgroud)
然后:
- (void)handleTapGesture:(UITapGestureRecognizer *)sender
{
if( ((UIImageView *) sender.view).tag == 0 ) // Check the identifier
{
// Your code here
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1912 次 |
| 最近记录: |