karthikeyan
karthikeyan

Reputation: 3898

How to create custom delegate in iOS 8?

I have created delegate method and working in Xcode lower version but not working in Xcode 6.1.

Its showing error Cannot Find protocol declaration NSObject

Tried code: .h file

@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 file

 #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];
    }

Upvotes: 0

Views: 697

Answers (1)

Bevin Patel
Bevin Patel

Reputation: 302

Hey You can solve you problem by following change in your .h file.

#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

Upvotes: 6

Related Questions