开发者

UIView Subclass not working

I have an XCode project I am working on that has multiple views controlled by a tabBar that is throwing multiple instances of the error:

"cannot find interface declaration for '~my sub view name~', superclass of '~my sub view name~'

These sub views were created after the original project as new files. Each has a line of code like this:

@interface meViewAndEdit : meViewAndEdit

I see no #import statements either. The project fails to build and I am not sure what i should be setting these to. Should I be referencing my App delegate as the superclass? what is missing here?


UPDATE: (updated)

I changed the interface statements for each of my header files for the views i created as follows

@interface friends : UIView

BUT, it se开发者_运维问答ems that i have a new issue that i'll have to research:

"UIView" may not response to "initWithNibName.bundle"

This is now present in each of the .m files for the views I created.

still learning, thanks in advance for your input.


When declaring a class in Objective-C, you need to specify the class name, as well as the superclass. In your code @interface meViewAndEdit : meViewAndEdit, you are essentially declaring a class that is a subclass of itself. Since you are trying to create a subclass of UIView, the class declaration should look as follows: @interface meViewAndEdit : UIView.

Also, in a comment in another answer, you asked whether or not you need to #import the app delegate in every class. The answer to this is usually no, unless you specifically need to access something involving your specific app delegate class.

I will also make note that it is conventional to give classes a capitalized name. For example, it should be MeViewAndEdit, rather than meViewAndEdit. You only should keep the first letter lowercase if it is the name of a variable or function.

EDIT: The reason that you are encountering the errors in your update is that you are trying to subclass UIViewController, not UIView. On top of this, instead of subclassing either one, you are subclassing the app delegate. Change your line of code @interface subviewname : my_app_delegate to @interface subviewname : UIViewController. You are trying to create a subclass of UIViewController, not my_app_delegate.

On another conventional note, it is never good to put underscores in a class name. Always name classes in camel case like MyAppDelegate, not my_app_delegate.


You need to #include the .h header files in all classes in which you are using them.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜