UISearchBar Cancel Button

前端 未结 6 2745
别那么骄傲
别那么骄傲 2021-02-20 03:35

Using a UISearchBar with showCancelButton=YES on iOS 5. Would like the cancel button to stay enabled when the keyboard drops down. Using the following code seems not to work:<

6条回答
  •  北恋
    北恋 (楼主)
    2021-02-20 04:32

    I had to solve the same problem in my application. Try doing your above code after a fractional delay, e.g.

    [self performSelector:@selector(delayedEnable:) withObject:cancelButton afterDelay:0.001];
    
    - (void)delayedEnable:(UIButton*)button {
        button.enabled = YES;
    }
    

    It's ugly, but that's what it took to work for me. Alternatively, if you actually use a UISearchDisplayController to display the results, it should also fix the cancel button behavior for you (I think - I've delved into this issue less).

提交回复
热议问题