Xcode 4.3.2 给出错误“无法使用超级,因为它是根类”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10113669/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 23:56:54  来源:igfitidea点击:

Xcode 4.3.2 gives error "cannot use super because it is a root class"

iosxcode

提问by Ashan Marla

Lately when I updated to xcode 4.3.2 I've run into numerous new problems. In my app view controller m file, I keep getting the error "cannot use super because it is a root clause."

最近,当我更新到 xcode 4.3.2 时,我遇到了许多新问题。在我的应用程序视图控制器 m 文件中,我不断收到错误“无法使用超级,因为它是根子句”。

I've looked on the internet for hours, so any help would be appreciated.

我已经在互联网上看了几个小时,所以任何帮助将不胜感激。

Thanks

谢谢

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:    (UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

@end

回答by skh

This error may also come up if your class inherits from another custom class and if you used a forward declaration of your ancestor class (@class MyAncestorClass) in your header file, but forgot to #importyour ancestor class in the implementation file.

如果您的类继承自另一个自定义类,并且您@class MyAncestorClass在头文件中使用了祖先类 ( )的前向声明,但#import在实现文件中忘记了祖先类,则也可能出现此错误。

回答by Ken Thomases

When you declared your class, you probably forgot the superclass in the @interfaceline. For example, you did

当你声明你的类时,你可能忘记了@interface行中的超类。例如,你做了

@interface MyClass
{
    // ... ivars ...
}

// ... methods ...

@end

You want that first line to be:

您希望第一行是:

@interface MyClass : NSObject

or whatever superclass you intended to use.

或您打算使用的任何超类。

回答by raghul

Use this solution will help incase you encountered this problem in phonegap

使用此解决方案将帮助您在 phonegap 中遇到此问题

#import <Cordova/CDVViewController.h>
#import <Cordova/CDVCommandDelegateImpl.h>
#import <Cordova/CDVCommandQueue.h>

@interface MainViewController : CDVViewController
@end

@interface MainCommandDelegate : CDVCommandDelegateImpl
@end

@interface MainCommandQueue : CDVCommandQueue
@end