采用课程目标c时"找不到......的协议声明"

RBI*_*RBI 4 delegates protocols objective-c

目前,我对Objective-c中的自定义委托流程感到有点沮丧.我已经使用过几次设计模式,对它的工作方式有了很好的理解.我在互联网上搜索了2个小时试图找到我在这种情况下做错了什么,并且没有占上风.我还比较了我过去使用的正常运行的自定义委托与此实例的比较,并且看不出任何概念上的差异.所以我们走了:

我正在制作一个自定义的双表视图(一个表用于列表,另一个用于保存从该列表中进行的选择.)以便用户可以进行基本选择.这是头文件:

#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
Run Code Online (Sandbox Code Playgroud)

注意正式的协议声明.另请注意,这与.m文件一起编译正常.当我尝试编写一个类来采用协议时,我得到错误"无法找到"ListSelectorDataSoure""的协议声明.我也得到了"ListSelectorViewDelegate"的相同消息.这是委托类的.h文件:

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

@interface ListSelectorDelegateTemplate : NSObject 
 <ListSelectorDataSource,ListSelectorViewDelegate>{

}

@end
Run Code Online (Sandbox Code Playgroud)

请注意,我正在导入ListSelectorViewController.h,其中找到协议声明.另请注意,在键入""时,它会自动完成,这意味着它确实可以看到它.就像我说的那样,我已经完全按照其他对象的方式完成了它,没有任何问题,无法绕过这一个...任何帮助都将非常感激

RBI*_*RBI 8

好想通了......这里非常愚蠢的答案......

我最初在一个单独的项目中创建了ListSelectorViewController并将其添加到我正在处理的当前项目中...由于某种原因,.h和.m对于项目的其余部分是不可见的并且是错误的原因.只需将新文件添加到项目中并复制原始类的内容即可.


小智 5

今天也遇到了这个问题.这确实是一个xcode错误.

我的委托协议文件是由git merge conflict修改的,我修复了冲突,但是我使用这个委托的所有文件仍然找不到这个委托协议文件.

所以我通过引用删除这两个文件,并再次将它们添加到项目中.有效!