我做了一些搜索,但答案仍然不清楚。我正在尝试在 TableViewController (TVC)内创建 UISearchDisplayController 的实例。
在我的 TVC 的标题中,我将 searchDisplayController 声明为属性:
@interface SDCSecondTableViewController : UITableViewController
@property (nonatomic, strong) NSArray *productList;
@property (nonatomic, strong) NSMutableArray *filteredProductList;
@property (nonatomic, strong) UISearchDisplayController *searchDisplayController;
@end
这样做会产生错误:
属性“searchDisplayController”尝试使用超类“UIViewController”中声明的实例变量“_searchDisplayController”
Adding @synthesize searchDisplayController
在实现文件中消除了错误。
谁能帮我理解这个错误吗?我使用的是 Xcode 4.6.2,但我的印象是从 Xcode 4.4 开始自动合成属性。
你不应该打电话[self performSelector:@selector(setSearchDisplayController:) withObject:searchDisplayController];
正如 LucOlivierDB 建议的那样。这是一个私有 API 调用,它会让你的应用程序被 Apple 拒绝(我知道,因为它发生在我身上)。相反,只需这样做:
@interface YourViewController ()
@property (nonatomic, strong) UISearchDisplayController *searchController;
@end
@implementation YourViewController
-(void)viewDidLoad{
[super viewDidLoad];
UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
searchBar.delegate = self;
self.searchController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
self.searchController.delegate = self;
self.searchController.searchResultsDataSource = self;
self.searchController.searchResultsDelegate = self;
self.tableView.tableHeaderView = self.searchBar;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)