我遇到了我設置的代理的奇怪問題。我得到的錯誤是「無法找到協議聲明 'SearchViewDelegate'找不到我的自定義代理的協議聲明
ListViewController.h
#import "SearchView.h"
@class SearchView;
@protocol SearchViewDelegate <NSObject>
@optional
- (void)didTapSearchButton:(SearchView *)searchView;
@end
@interface TaskListViewController : UIViewController <UITableViewDelegate,UITableViewDataSource, UITextFieldDelegate>{
SearchView *searchView;
}
@property(nonatomic, assign) id<SearchViewDelegate> delegate;
ListViewController.m
- (IBAction)didTapSearchButton
{
NSString *searchTerm = searchView.searchField.text;
if ([searchTerm isEqualToString:@""]) {
[self.view endEditing:YES];
return ;
}
[searchView resignFirstResponder];
NSArray *results = [[CoreDataManager sharedInstance] fetchTaskByName:searchTerm];
[tasks removeAllObjects];
[tasks addObjectsFromArray:results];
[self.view endEditing:YES];
[taskTable reloadData];
}
SearchView.h
#import <UIKit/UIKit.h>
@interface SearchView : UIView <UITextFieldDelegate, UISearchBarDelegate, SearchViewDelegate> // <- where the protocol error occurrs
@property (nonatomic, strong) UITextField *searchField;
@property (nonatomic, strong) UIButton *searchButton;
@end
我想我正確地宣佈了代表和一切。
這裏就是我要調用的委託方法,在searchView.m:
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[self.searchField.delegate didTapSearchButton:self];
[textField resignFirstResponder];
return YES;
}
嘗試過,但是錯誤仍然存在 – OxenBoxen
錯誤來自SearchView界面或實施? –