4

I'm a little frustrated at the moment with the custom delegate process in objective-c. I've used the design pattern a few times already and have a pretty good understanding of how it works. I've searched the internet for 2 hours trying to find what I'm doing wrong in this instance, and to no prevail. I also compared my past use of custom delegates that are functioning properly vs. this instance and can't see any conceptual difference. so here we go:

I'm making a custom dual table view (one table for the list, and the other to hold the selections made from that list.) so that the user can make basic selections. here is the header file:

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>


@protocol ListSelectorViewDelegate

-(void) listTableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
-(void) selectTableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;

-(void) listTableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath;
-(void) selectTableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath;

- (void)listTableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath;
- (void)selectTableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath;

@end


@protocol ListSelectorDataSource

-(UITableViewCell *)listTableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
-(UITableViewCell *)selectTableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;

-(NSArray *)sectionIndexTitlesForListTableView:(UITableView *)tableView editStatus:(BOOL) status;
-(NSArray *)sectionIndexTitlesForSelectTableView:(UITableView *)tableView editStatus:(BOOL) status;

-(NSInteger)listTableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index;
-(NSInteger)selectTableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index;

@end

@interface ListSelectorViewController : UIViewController {

 //Delegate
 id <ListSelectorViewDelegate> listsDelegate;
 id <ListSelectorDataSource> listsDataSource;

 //Titles
 IBOutlet UINavigationBar *pageNavBar;
 IBOutlet UINavigationBar *selectNavBar;
 IBOutlet UINavigationBar *listNavBar;

 //Tables
 IBOutlet UITableView *selectTable;
 IBOutlet UITableView *listTable;

 //Table Data
 NSMutableArray *listItems;
 NSMutableArray *selectItems;

 //Search Bars
 IBOutlet UISearchBar *selectedSearch;
 IBOutlet UISearchBar *listSearch;
 BOOL listTableIsSearching;
 BOOL selectTableIsSearching;

}

@property(nonatomic,assign) id <ListSelectorViewDelegate> listsDelegate;
@property(nonatomic,assign) id <ListSelectorDataSource> listsDataSource;


-(IBAction) newItem:(id)sender;
-(IBAction) selectAll:(id)sender;
-(IBAction) clearSelections:(id)sender;

@end

Notice the formal protocol declarations. Also note that this, along with the .m file compile fine. When I try to write a class to adopt the protocol I get the error "Cannot find protocol declaration for "ListSelectorDataSoure" ". I get the same message for the "ListSelectorViewDelegate" as well. Here is the .h file for the delegate class:

#import <Foundation/Foundation.h>
#import"ListSelectorViewController.h"

@interface ListSelectorDelegateTemplate : NSObject 
 <ListSelectorDataSource,ListSelectorViewDelegate>{

}

@end

Note that I am importing the ListSelectorViewController.h where the protocol declarations are found. Also note that when typing " " it does auto complete which means it does see it. Like I said, I've done it this exact way for other objects with no issues and cannot wrap my head around this one ... Any Help at all would be greatly appreciated

RBI
  • 803
  • 2
  • 14
  • 25
  • I notice a typo in your compiler error: `ListSelectorDataSoure`. It's not just that is it? –  Dec 18 '10 at 17:32
  • Thanks for noticing but no that was just me typing the error in my question instead of copy/pasting it... I have yet to figure out why it won't build – RBI Dec 18 '10 at 22:00

7 Answers7

8

Ok figured it out.... extremely stupid answer here...

I originally created the ListSelectorViewController in a separate project and added it to the current project I'm working on... for some reason the .h and .m were not visible to the rest of the project and was the reason for the errors. simply added a new file to the project and copied over the contents of the original class.

RBI
  • 803
  • 2
  • 14
  • 25
5

Got this problem today too. It is a xcode bug indeed.

my delegate protocol file was modified by git merge confliction, I fixed the confliction, but all my files using this delegate still cannot find this delegate protocol file.

so i delete these two files by reference ,and add them to project again. it worked!

phenmod
  • 141
  • 2
  • 6
2

If ListSelectorViewController.h also imports ListSelectorDelegateTemplate.h, you'll get errors like that. You should move any imports that you can into the ".m" file, and replace them with @class declarations if necessary.

Chuck
  • 234,037
  • 30
  • 302
  • 389
  • Thank you for your response. Unfortunately ListselectorViewController.h does not import ListSelectorDelegateTemplate.h. as you can see from the code above, the only imports for the viewController.h file are the UIKit and the Foundation libraries.... still stumped :( – RBI Dec 19 '10 at 01:20
0

You have put my protocol declaration on separate file and import it then

Saad Ur Rehman
  • 798
  • 1
  • 10
  • 19
0

what worked for me was cleaning the project (shift+command+K) simple.

Conflagrationator
  • 251
  • 1
  • 3
  • 8
0

In my case the error was caused by a cyclic #import. The delegate protocol declaration file included the implementor of the delegate . The implementor included the delegate protocol declaration file.

0

Got the same problem today. This seems to be a xcode bug.

Anyway my solution was to create an empty h. file, declare my protocol there, and then #import this new h. file anywhere where i was using it.

animal_chin
  • 6,610
  • 9
  • 37
  • 41