ios error with Xcode 6 '类'ViewController'的接口定义重复

zd287kbt  于 2023-08-08  发布在  iOS
关注(0)|答案(2)|浏览(81)

我正在使用Xcode 6编写一个应用程序,遵循2012年的基本教程。本教程是用Xcode 4.3编写的,我确信我完全按照它的要求做了,我仔细检查了问题区域。我对这种类型的编程很陌生,因为我通常处理游戏开发和机器人,但以前做过一点。
错误:
类“ViewController”的接口定义重复
这就是代码:

#import "ViewController.h"

 @interface ViewController // First error here.

 @end

 @implementation ViewController

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

   -(void) presentMessage:(NSString *)message {
       UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"My Title"         message: message delegate: nil cancelButtonTitle:@"Ok" otherButtonTitles: nil ];

[alert show];
[alert release]; // second error.
}

-(void) scheduleLocalNotificationWithDate:(NSDate *)fireDate {
UILocalNotification *notification = [[UILocalNotification alloc] init];

...    

[notification release]; // third error
}

-(IBAction) buttonTapped:(id)sender {

    dateFormatter...

[dateFormatter release]; // fourth error
 }
   @end

字符串
对不起,奇怪的格式,但我不能得到这个格式成代码。
先谢谢你了

wyyhbhjk

wyyhbhjk1#

简单的解决方案在这里..它为我工作
去编辑方案->选择构建->构建选项取消勾选并行构建
现在运行您的应用程序

xzv2uavs

xzv2uavs2#

您需要将()添加到@interface ViewController行。
@interface ViewController()
这在iOS中称为私有类别,它用于在实现文件中定义私有方法和属性。
在.h文件中,您会发现接口声明为@interface ViewController,这就是为什么编译器认为您声明了两次。使用私有类别(@interface ViewController())告诉编译器,您实际上正在扩展已定义接口(称为ViewController)的功能,添加私有方法和属性。

相关问题