ko1o / PYSearch

🔍 An elegant search controller which replaces the UISearchController for iOS (iPhone & iPad) .
MIT License
3.83k stars 752 forks source link

继承PYSearchViewController之后的Controller不走生命周期的方法 #135

Closed CainLuo closed 6 years ago

CainLuo commented 6 years ago

有一个场景我继承了一个PYSearchViewController在内部微调, 但是发现这个继承自的Controller不走- (void)viewWillAppear:(BOOL)animated, - (void)viewWillDisappear:(BOOL)animated, 这些方法

fakerlogic commented 6 years ago

try this

+ (instancetype)searchViewControllerWithHotSearches:(NSArray<NSString *> *)hotSearches searchBarPlaceholder:(NSString *)placeholder
{
    PYSearchViewController *searchVC = [[PYSearchViewController alloc] init];
    searchVC.hotSearches = hotSearches;
    searchVC.searchBar.placeholder = placeholder;
    return searchVC;
}

⬇️

+ (instancetype)searchViewControllerWithHotSearches:(NSArray<NSString *> *)hotSearches searchBarPlaceholder:(NSString *)placeholder
{
    PYSearchViewController *searchVC = [[self alloc] init];
    searchVC.hotSearches = hotSearches;
    searchVC.searchBar.placeholder = placeholder;
    return searchVC;
}
ko1o commented 6 years ago

@CainLuo @fakerlogic 确实是我的问题,这里应该是使用self进行创建!才能走继承类的方法!