重复的接口定义和预期的选择器错误

时间:2013-07-09 20:36:30

标签: ios objective-c xcode header-files

我一直在研究iPhone应用程序,今天遇到了2个错误,并且想知道是否有人能指出我修复它们的方向。首先,我在ViewController.h中有以下代码:

#import <UIKit/UIKit.h>

@interface CIAViewController : UIViewController {
//duplicate interface definition for class 'CIAViewController'
    IBOutlet UILabel *cruzia;
    IBOutlet UILabel *textarea;
    IBOutlet UIButton *playbtn;
    IBOutlet UIButton *tutorialbtn;
    IBOutlet UIButton *optionsbtn;
    IBOutlet UIButton *trainingbtn;
    IBOutlet UIButton *back;
}

-(IBAction)press;
-(IBAction)press2;
-(IBAction)press3;
-(IBAction)press4;
-(IBAction)press5;

我已经检查了整个项目,似乎找不到任何对接口定义的引用,但我只是一个编程的初学者,可能已经错过了一些东西。

另一个错误发生在ViewController.m中。

该文件的内容非常简单:

#import "CIAViewController.h"

@interface CIAViewController ()
@end
//Expected selector for Objective-C method

@implementation CIAViewController

-(IBAction)press {
    cruzia.hidden = 0;
    textarea.hidden = 0;
    playbtn.hidden = 1;
    tutorialbtn.hidden = 1;
    optionsbtn.hidden = 1;
    trainingbtn.hidden = 1;
    back.hidden = 0;
    cruzia.text = @"Play";
    textarea.text = @"Hello! You are playing the game of Cruzia!";
}

-(IBAction)press2 {
    cruzia.hidden = 0;
    textarea.hidden = 0;
    playbtn.hidden = 1;
    tutorialbtn.hidden = 1;
    optionsbtn.hidden = 1;
    trainingbtn.hidden = 1;
    back.hidden = 0;
    cruzia.text = @"Tutorial";
    textarea.text = @"Welcome! You are watching the Cruzia tutorial!";
}

-(IBAction)press3 {
    cruzia.hidden = 0;
    textarea.hidden = 0;
    playbtn.hidden = 1;
    tutorialbtn.hidden = 1;
    optionsbtn.hidden = 1;
    trainingbtn.hidden = 1;
    back.hidden = 0;
    cruzia.text = @"Options";
    textarea.text = @"You are now in the Options screen. You can edit the settings of the game!";
}

-(IBAction)press4 {
    cruzia.hidden = 0;
    textarea.hidden = 0;
    playbtn.hidden = 1;
    tutorialbtn.hidden = 1;
    optionsbtn.hidden = 1;
    trainingbtn.hidden = 1;
    back.hidden = 0;
    cruzia.text = @"Training";
    textarea.text = @"This is the training area. You can improve your Cruzia skills here!";
}

-(IBAction)press5 {
    cruzia.hidden = 0;
    textarea.hidden = 0;
    playbtn.hidden = 0;
    tutorialbtn.hidden = 0;
    optionsbtn.hidden = 0;
    trainingbtn.hidden = 0;
    back.hidden = 1;
    cruzia.text = @"Cruzia";
}


- (void)viewDidLoad
{
    textarea.hidden = 1;
    playbtn.hidden = 0;
    tutorialbtn.hidden = 0;
    optionsbtn.hidden = 0;
    trainingbtn.hidden = 0;
    back.hidden = 1;
    cruzia.text = @"Cruzia";
    [super viewDidLoad];
}

@end

我无法弄清楚为什么我会收到此错误(Objective-C方法的预期选择器),我们将非常感谢任何帮助。

另外,如果你有时间,我的IOS模拟器会出现轻微问题。每当我将我的项目发送到模拟器时,一半按钮工作,另一半工作,但没有文本。任何帮助解决这个问题都会很棒。

再次感谢, -George

1 个答案:

答案 0 :(得分:1)

CIAViewController.h头文件末尾缺少@end将导致这些类型的错误。当Xcode尝试编译您的CIAViewController.m文件时,它会看到#import "CIAViewController.h"指令,并且基本上将该头文件中的代码插入到.m文件的顶部。因此你有这个:

@interface CIAViewController : UIViewController {
    ....
}
- (IBAction)variousSelectorsHere;
@interface CIAViewController ()
@end
@implementation CIAViewController
...

在这些情况下,编译器真的很困惑,因为它无法告诉原始@interface声明的结束位置。根据经验,如果您在头文件中收到有关缺少类名称或其他有意义的错误的错误,请在头文件中查找缺少的大括号或@end关键字或查找头文件导入错误。

这有点类似于C和C ++中的情况,如果你没有include guards