Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective-C委托-在本例中无法查看委托的工作方式_Objective C_Delegates - Fatal编程技术网

Objective-C委托-在本例中无法查看委托的工作方式

Objective-C委托-在本例中无法查看委托的工作方式,objective-c,delegates,Objective C,Delegates,我在iPhone上运行一个应用程序,有一行代码如下: [self.searchControllerDelegate searchController:self didSelectSearchTerm:search.text]; .h文件定义委托和属性: @protocol NBMSearchViewControllerDelegate <NSObject> - (void)searchController:(NBMSearchViewController *)controller

我在iPhone上运行一个应用程序,有一行代码如下:

[self.searchControllerDelegate searchController:self didSelectSearchTerm:search.text];
.h
文件定义委托和属性:

@protocol NBMSearchViewControllerDelegate <NSObject> 
- (void)searchController:(NBMSearchViewController *)controller didSelectSearchTerm:(NSString *)term;
@end
@property (weak, nonatomic) IBOutlet id<NBMSearchViewControllerDelegate> searchControllerDelegate;
我在
setupApplicationForiPhone
方法中没有看到对
searchControllerDelegate
的引用(fwiw,在
setupApplicationForiPad
方法中有一个

困惑。有人能解释一下吗?

这个项目可以

AppDelegate
中,将对象设置为NBMSearchViewController
delegate
,因为有两个不同的
UIViewControllers
初始化,这取决于启动应用程序的平台(iPhone/iPad)。在我看来,iPhone上不可能进行搜索

您还可以使用CMD选择委托方法,然后获得将在何处执行这些方法的提示:


不太可能,因为这是您的代码库,而且听起来像是基于文本搜索的问题(对
searchControllerDelegate
的全局搜索)。代理是否在iPhone上调用?代码库来自“使用UI自动化测试iOS应用程序”一书。不,我没有看到代表在iPhone上被调用。所以听起来你已经有了答案,大概你在iPad上看到了答案
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
    [self setupApplicationForiPad];
} else {
    [self setupApplicationForiPhone];
}