被触摸的UIView的名称 [英] name of UIView that was touched

查看:107
本文介绍了被触摸的UIView的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在touchesbegan事件中获取[触摸视图]的名称。
所以如果它是UIView * aaaaaview我会得到aaaaaview作为返回;
谢谢你,
nonono

How can I get the name of the [touch view] in the touchesbegan event. So if it were UIView *aaaaaview I would get aaaaaview as the return; Thank You, nonono

推荐答案

UIView * aaaaaView只是指内存中的一个地方。所以如果你有

"UIView *aaaaaView" just refers to a place in memory. So if you had

UIView *aView;
UIView *anotherView;
aView = anotherView;

并且用户触摸了一个UIView,视图的名称是aView还是anotherView?特别是,一个UIView不知道你用来存储它的变量的名称。

and the user touched a UIView, would the view's name be "aView" or "anotherView"? In particular, a UIView has no knowledge of the name of the variable you use to store it.

我想你将不得不初始化一个NSDictionary映射名称UIViews。

I think you're going to have to initialise an NSDictionary mapping names to UIViews.

您的-viewDidLoad中可能有以下内容:

Something in your -viewDidLoad like this, perhaps:

yourDictionary = [[NSDictionary alloc] initWithObjectsAndKeys:
                          @"aaaaaView", aaaaaView, @"viewTwo", viewTwo, nil];

,然后在您的活动中可以说

and then in your event you can say

NSString *viewName = (NSString *) [yourDictionary objectForKey: [touch view]];

这篇关于被触摸的UIView的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆