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

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

\"enter \"enter

11条回答
  •  轮回少年
    2020-12-30 02:26

    Since iOS 7 all the subview of UISearchBar are one level deeper. This should work:

    for (UIView *subView in searchBar.subviews) {
        for (UIView *secondLevelSubview in subView.subviews) {
            if ([view isKindOfClass:[UIButton class]]) {
               [(UIButton *)view setEnabled:YES];
            }
    }
    

    Still hacky and can easily break in the next iOS version.

提交回复
热议问题