这是代码:
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@protocol HomeHeaderCellDelegate <NSObject>
- (void)didTapMoreLessMenuButton:(HomeHeaderCell *)cell;
@end
@interface HomeHeaderCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UIView *secondMenuRowView;
@property (weak, nonatomic) IBOutlet UIButton *moreLessMenuButton;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *secondMenuRowViewHeightConstraint;
@property (weak, nonatomic) IBOutlet UIButton *askButton;
@property (weak, nonatomic) IBOutlet UIButton *contactButton;
@property (weak, nonatomic) IBOutlet UIButton *benchmarkButton;
@property (weak, nonatomic) IBOutlet UIButton *buySellButton;
@property (weak, nonatomic) IBOutlet UIButton *marketButton;
@property (nonatomic, weak) id <HomeHeaderCellDelegate> delegate;
@property BOOL isFullMenu;
- (void)toggleHeight;
@end
NS_ASSUME_NONNULL_END
此行有错误
- (void)didTapMoreLessMenuButton:(HomeHeaderCell *)cell;
它说:
期望类型
编译器需要知道 HomeHeaderCell
在某个地方声明。
实际上,您必须 import 带有@import
语句的类,但是在这种情况下,您只需要类型而不是实现详细信息。@class
指令是一个正向参考,可确认类型但避免循环参考问题。
在进口行下方添加 @class
,顺便说一句,使用现代@import
语句。
@import UIKit;
@class HomeHeaderCell;
您可以做
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@protocol HomeHeaderCellDelegate;
@interface HomeHeaderCell : UITableViewCell
@property (nonatomic, weak) id <HomeHeaderCellDelegate> delegate;
@end
@protocol HomeHeaderCellDelegate <NSObject>
- (void)didTapMoreLessMenuButton:(HomeHeaderCell *)cell;
@end
NS_ASSUME_NONNULL_END