addSubview with NSObject?
I have a class which is an NSObject type,开发者_Go百科 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?
The addSubview:
method only takes instances of UIView
. It won't work with NSObject
.
Check out the method specification in the Apple Docs
You need the object you're adding to be of the type UIView
or inherit from it. In your class declaration, simply put:
@interface MyClasS : 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:
UIView *v = (UIView *)nsSubview ;
[ self.view addSubview:v] ;
精彩评论