OxenBoxen
OxenBoxen

Reputation: 165

cannot find protocol declaration with my custom delegate

I am running into a weird problem with my delegate that I set up. the error I get is "Cannot find protocol declaration for '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

I thought I declared the delegate correctly and everything.

Here is where I want to call the delegate method, in searchView.m:

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
  [self.searchField.delegate  didTapSearchButton:self];
  [textField resignFirstResponder];
  return YES;
}

Upvotes: 1

Views: 862

Answers (2)

Pei
Pei

Reputation: 11643

You should have delegate protocal declaration (I assume it's SearchViewDelegate in your case) in SearchView.h. That's standard way in delegate pattern.

Upvotes: 1

James Paolantonio
James Paolantonio

Reputation: 2194

If the error is in SearchView.h, I think you need to add

#import "TaskListViewController.h"

to the header.

Upvotes: 0

Related Questions