Objective-C类别的问题

jos*_*im5 2 iphone objective-c categories

以下代码给出了一个错误"无法找到'StartTimerViewController'的接口声明

#import "StartTimerViewController.h"

@interface StartTimerViewController (timerMethods) 

-(void)startTimer:(id)sender withTimeIntervalInSeconds:(NSTimeInterval)time 
        andMessage:(NSString *)message
notificationChoice:(BOOL)notificationChoice
      andWithLabel:(UILabel *)theLabel;

-(void)updateLabel:(NSTimer *)timer;

@end
Run Code Online (Sandbox Code Playgroud)

为什么会这样?StartTimerViewController.h确实存在,并且是我编码的有效类.这个文件应该是一个扩展StartTimerViewController的类别.

这是StartTimerViewController.h的开头

#import <UIKit/UIKit.h>
#import "StartTimerViewController+timerMethods.h"

@interface StartTimerViewController : UIViewController {
Run Code Online (Sandbox Code Playgroud)

Mys*_*ral 7

你有一个循环参考.你不能在StartTimerViewController.h中包含timermethods.h,因为timerMethods.h需要StartTimerViewController.h.您永远不需要父母知道类别,只有类别需要知道父类.

祝好运!