How do you keep the cancel button in the search bar enabled when the keyboard is dismissed?

前端 未结 11 1768
萌比男神i
萌比男神i 2020-12-30 01:23

\"enter \"enter

11条回答
  •  时光取名叫无心
    2020-12-30 02:14

    You could do this:

    - (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {
        [self enableCancelButton];
    }
    
    - (void)enableCancelButton {
        for (UIView *view in _seachBar.subviews) {
            if ([view isKindOfClass:[UIButton class]]) {
                [(UIButton *)view setEnabled:YES];
            }
        }
    }
    

    BUT this is a pretty hackish method and I'm fairly certain it's generally frowned upon by Apple and could potentially lead to the app being rejected. As far as I know, there doesn't seem to be any other way to do what you're trying to do.

提交回复
热议问题