gpt4 book ai didi

ios - 如何在 iOS 8 中创建自定义委托(delegate)?

转载 作者:行者123 更新时间:2023-11-28 18:17:59 25 4
gpt4 key购买 nike

我已经创建了委托(delegate)方法并在较低版本的 Xcode 中工作,但在 Xcode 6.1 中无法工作。

显示错误Cannot Find protocol declaration NSObject

尝试过的代码:.h文件

@class ReportCell;
@protocol keyboardDelegate <NSObject>

@optional
- (BOOL)leaveKeyboard:(ReportCell *)cell ;

@end


#import <UIKit/UIKit.h>

@interface ReportCell : UITableViewCell
@property (strong, nonatomic) IBOutlet UIImageView *imgReport;
@property (strong, nonatomic) IBOutlet UITextField *txtReport;
@property (strong, nonatomic) IBOutlet UIView *viewReport;
@property (nonatomic, assign) id <keyboardDelegate> delegate;

@end

.m 文件

 #import "ReportCell.h"

@implementation ReportCell

- (void)awakeFromNib
{
// Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];

// Configure the view for the selected state
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{

[_delegate leaveKeyboard:self];
[self.superview endEditing:YES];
[super touchesBegan:touches withEvent:event];
}

最佳答案

嘿,您可以通过更改 .h 文件来解决您的问题。

#import <UIKit/UIKit.h>

@class ReportCell;
@protocol keyboardDelegate;

@interface ReportCell : UITableViewCell
@property (strong, nonatomic) IBOutlet UIImageView *imgReport;
@property (strong, nonatomic) IBOutlet UITextField *txtReport;
@property (strong, nonatomic) IBOutlet UIView *viewReport;
@property (nonatomic, assign) id <keyboardDelegate> delegate;
@end

@protocol keyboardDelegate <NSObject>
@optional
- (BOOL)leaveKeyboard:(ReportCell *)cell ;
@end

关于ios - 如何在 iOS 8 中创建自定义委托(delegate)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29251971/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com