【发布时间】:2014-11-17 21:00:32
【问题描述】:
目前我对 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
注意正式的协议声明。另请注意,这与 .m 文件一起编译得很好。当我尝试编写一个类来采用协议时,我收到错误“找不到“ListSelectorDataSoure”的协议声明”。对于“ListSelectorViewDelegate”,我也收到了相同的消息。这是委托类的 .h 文件:
#import <Foundation/Foundation.h>
#import"ListSelectorViewController.h"
@interface ListSelectorDelegateTemplate : NSObject
<ListSelectorDataSource,ListSelectorViewDelegate>{
}
@end
请注意,我正在导入找到协议声明的 ListSelectorViewController.h。另请注意,当键入“”时,它会自动完成,这意味着它确实可以看到它。就像我说的那样,我已经为其他没有问题的对象以这种方式完成了它,并且无法将我的头包裹在这个对象上......任何帮助将不胜感激
【问题讨论】:
-
我注意到您的编译器错误中有一个错字:
ListSelectorDataSoure。不只是这样吗? -
感谢您的注意,但这只是我在我的问题中输入错误而不是复制/粘贴它......我还没有弄清楚为什么它不会构建
标签: objective-c delegates protocols