[Objective-C]导入视图控制器为代表团不工作

发布时间: 2016/9/23 2:16:29
注意事项: 本文中文内容可能为机器翻译,如要查看英文原文请点击上面连接.

我有一个视图控制器,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' 超类不确信此错误发生的原因。任何意见将帮助。

解决方法 1:

保持在相同的委托 .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
官方微信
官方QQ群
31647020