我有一些符合协议的自定义视图:
class CustomView1: UIView, MyProtocol {
...
}
class CustomView2: UIView, MyProtocol {
...
}然后,我想通过检查视图是否符合我的协议来检查视图是不是我的自定义视图,但它不起作用:
let v = view.viewWithTag(1000)
if let _ = v as? MyProtocol {
print("this is my custom view")
}
if v.self is MyProtocol.Type {
print("this is my custom view")
}有什么想法吗?
谢谢!
发布于 2018-07-16 12:43:27
在代码中一切都很好,我认为让v= view.viewWithTag(1000)在中得到的值为零
我在游乐场检查过你的代码,它工作得很好。

https://stackoverflow.com/questions/51354562
复制相似问题