gpt4 book ai didi

iphone - 找不到我的自定义委托(delegate)的协议(protocol)声明

转载 作者:行者123 更新时间:2023-11-29 13:02:24 26 4
gpt4 key购买 nike

我设置的委托(delegate)遇到了一个奇怪的问题。我得到的错误是“找不到‘SearchViewDelegate’的协议(protocol)声明

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];
}

搜索 View .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

我以为我正确地声明了委托(delegate)和所有内容。

这是我想在 searchView.m 中调用委托(delegate)方法的地方:

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

最佳答案

您应该在 SearchView.h 中有委托(delegate)协议(protocol)声明(我假设在您的情况下是 SearchViewDelegate)。这是委托(delegate)模式中的标准方式。

关于iphone - 找不到我的自定义委托(delegate)的协议(protocol)声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19456120/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com