使用 NSObject 添加子视图?
我有一个 NSObject 类型的类,在视图中它不允许我放置:
[self.view addSubview:nsObject];
因为它是不兼容的类型。我怎样才能让它发挥作用?
I have a class which is an NSObject type, and in a view it won't let me put:
[self.view addSubview:nsObject];
because it's an incompatible type. How can i get this to work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
addSubview:
方法仅采用UIView
的实例。它不适用于NSObject
。查看 Apple Docs< 中的方法规范/a>
The
addSubview:
method only takes instances ofUIView
. It won't work withNSObject
.Check out the method specification in the Apple Docs
您需要添加的对象属于
UIView
类型或从其继承。在你的类声明中,简单地说:You need the object you're adding to be of the type
UIView
or inherit from it. In your class declaration, simply put:我假设 nsSubview 是 UIView 的子类,只需输入 arg 传递编译器就会将其视为 NSObject?或者它是某种包含 UIView 的包装对象?你可以尝试:
I assume that nsSubview is a subclass of UIView and just by typing, arg passing the compiler is seeing it as an NSObject? Or is it some kind of wrapper object that contains a UIView? You could try: