Jdi*_*zle 3 properties searchdisplaycontroller ios xcode4.6
我做了一些搜索,答案仍然不清楚.我试图在TableViewController(TVC)中创建一个UISearchDisplayController的实例.
在我的TVC的标题中,我将searchDisplayController声明为属性:
@interface SDCSecondTableViewController : UITableViewController
@property (nonatomic, strong) NSArray *productList;
@property (nonatomic, strong) NSMutableArray *filteredProductList;
@property (nonatomic, strong) UISearchDisplayController *searchDisplayController;
@end
Run Code Online (Sandbox Code Playgroud)
这样做会产生错误:
属性'searchDisplayController'试图使用超类'UIViewController'中声明的实例变量'_searchDisplayController'
添加@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;
Run Code Online (Sandbox Code Playgroud)
}