2015-03-25 69 views
0

我已經創建了委託方法,並在Xcode的低版本中工作,但不能在Xcode 6.1中工作。如何在iOS 8中創建自定義委託?

其示值誤差找不到協議聲明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]; 
    } 

回答

6

嘿,你能解決你問題b在您的.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 
+1

-Excellant answer這對我們非常有幫助,謝謝! – Hardy 2015-04-08 06:43:34