Search code examples
iosviewuitextfielduisearchbaruiactionsheet

UIAlertAction Triggers SearchBar TextDidBeginEditing Unexpectedly


It seems that the presentation of a UIActionController seems to somehow call my search bar text fields textDidBeginEditing method. The controller is initially presented right after the search bar has resigned first responder. Is this the expected behavior of an UIActionController? Is it meant to reactivate the previously active search bar once it is dismissed?

Any help would be great!

Edit:

I set a breakpoint on the search bars didBeginEditing method and then did a backtrace to try to see who is calling the method to begin with(not sure if this is the right way to go about his). This is what I got... Does this help at all... any ideas?

frame #1: 0x0000000189a9f4cc UIKit`-[UISearchBar(UISearchBarStatic) _searchFieldBeginEditing] + 84
frame #2: 0x00000001898dd398 UIKit`-[UIApplication sendAction:to:from:forEvent:] + 96
frame #3: 0x00000001898c6474 UIKit`-[UIControl _sendActionsForEvents:withEvent:] + 612
frame #4: 0x00000001898c5824 UIKit`-[UITextField willAttachFieldEditor:] + 764
frame #5: 0x00000001898c21c4 UIKit`-[UIFieldEditor becomeFieldEditorForView:] + 884
frame #6: 0x00000001899ab200 UIKit`-[UITextField _becomeFirstResponder] + 168
frame #7: 0x0000000189a9f300 UIKit`-[UISearchBarTextField _becomeFirstResponder] + 108
frame #8: 0x0000000189aa1f88 UIKit`-[UITextField __resumeBecomeFirstResponder] + 68
frame #9: 0x0000000189af6ad4 UIKit`__45-[UISearchBarTextField _becomeFirstResponder]_block_invoke + 316
frame #10: 0x0000000189a9f474 UIKit`-[UISearchBarTextField _becomeFirstResponder] + 480
frame #11: 0x000000018992ad28 UIKit`-[UIResponder becomeFirstResponder] + 392
frame #12: 0x000000018992b0ac UIKit`-[UIView(Hierarchy) becomeFirstResponder] + 124
frame #13: 0x00000001899a9de4 UIKit`-[UITextField becomeFirstResponder] + 68
frame #14: 0x0000000189988698 UIKit`-[UIPeripheralHost(UIKitInternal) _restoreInputViewsWithId:animated:] + 356
frame #15: 0x0000000189bcd9c8 UIKit`-[UIViewController _dismissViewControllerWithAnimationController:interactionController:completion:] + 1020
frame #16: 0x00000001899d02f8 UIKit`-[UIViewController _dismissViewControllerWithTransition:from:completion:] + 852
frame #17: 0x0000000189978388 UIKit`-[UIViewController dismissViewControllerWithTransition:completion:] + 1036
frame #18: 0x0000000189977f1c UIKit`-[UIViewController dismissViewControllerAnimated:completion:] + 252
frame #19: 0x0000000189c86f24 UIKit`-[UIAlertController _dismissAnimated:triggeringAction:triggeredByPopoverDimmingView:] + 420
frame #20: 0x000000018989bf54 UIKit`_UIGestureRecognizerUpdate + 8536
frame #21: 0x0000000184de82a4 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 32
frame #22: 0x0000000184de5230 CoreFoundation`__CFRunLoopDoObservers + 360
frame #23: 0x0000000184de5610 CoreFoundation`__CFRunLoopRun + 836
frame #24: 0x0000000184d112d4 CoreFoundation`CFRunLoopRunSpecific + 396
frame #25: 0x000000018e7676fc GraphicsServices`GSEventRunModal + 168
frame #26: 0x000000018990ef40 UIKit`UIApplicationMain + 1488
frame #27: 0x00000001000ce974 Squirrel`main(argc=1, argv=0x000000016fd539d0) + 124 at main.m:14
frame #28: 0x00000001971a6a08 libdyld.dylib`start + 4

Solution

  • This fixed the issue. https://stackoverflow.com/a/24854803/3688923

    [[NSOperationQueue mainQueue]addOperationWithBlock:^{
        [self presentViewController:alert animated:YES completion:nil];
    }];