UIView作为字典键? [英] UIView as dictionary key?

查看:222
本文介绍了UIView作为字典键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望有一个 NSDictionary ,它从 UIView 映射到其他地方。

I want to have a NSDictionary that maps from UIViews to something else.

但是,由于UIViews没有实现 NSCopying 协议,我不能直接将它们用作字典键。

However, since UIViews do not implement the NSCopying protocol, I can't use them directly as dictionary keys.

推荐答案

您可以使用 NSValue 按住指向<$的指针c $ c> UIView 并将其用作密钥。 NSValues
是可复制的。但是,如果视图被销毁, NSValue 将持有
垃圾指针。

You can use an NSValue holding the pointer to the UIView and use this as key. NSValues are copyable. but, if the view is destroyed, the NSValue will hold a junk pointer.

这篇关于UIView作为字典键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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