0

我有一个视图控制器 FirstViewController,它有一个子类 FourthViewController。FirstViewController 的接口是:

#import "FourthViewController.h"
@interface FirstViewController : UIViewController <FourthViewControllerDelegate>

在 FourthViewController 的 .h 中,我有:

#import "FirstViewController.h"

@protocol FourthViewControllerDelegate
-(void) updateLabel;
@end

@interface FourthViewController : FirstViewController 

@property (weak, nonatomic) id<FourthViewControllerDelegate>delegate;

这给了我错误消息:找不到'FirstViewController'的接口声明,'FourthViewController'的超类我不确定为什么会发生这个错误。任何建议都会有所帮助。

4

1 回答 1

0

将委托.h与控制器保存在同一个文件中对您来说真的很重要吗?我把它放到一个单独的.h文件中,整个过程对我有用。像这样:

//FirstViewController.h
#import <Foundation/Foundation.h>

#import "FourthViewControllerDelegate.h"
@interface FirstViewController : UIViewController <FourthViewControllerDelegate>
@end

//FourthViewControllerDelegate.h
#import <Foundation/Foundation.h>

@protocol FourthViewControllerDelegate <NSObject>
-(void) updateLabel;
@end

//FourthViewController.h
#import <Foundation/Foundation.h>

#import "FirstViewController.h"
#import "FourthViewControllerDelegate.h"

@interface FourthViewController : FirstViewController

@property (weak, nonatomic) id<FourthViewControllerDelegate>delegate;
@end
于 2013-08-13T00:56:05.307 回答