iOS 13 : Searchbar crashing when cancel is hit repeatedly

标签 ios swift uisearchbar ios13 uisearchcontroller

当用户重复单击取消按钮时,我遇到崩溃:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Nested internal _UISearchBar transitions not yet supported. This is an internal UIKit bug.'

步骤:

  • 启动一个显示搜索栏的窗口。
  • 使搜索栏文本字段成为第一响应者。我启用了取消按钮,因此它会显示。
  • 点击取消按钮的位置几次。
  • 观察应用崩溃。

日志:

*** First throw call stack:
(
    0   CoreFoundation                      0x00007fff23b98bde __exceptionPreprocess + 350
    1   libobjc.A.dylib                     0x00007fff503b5b20 objc_exception_throw + 48
    2   CoreFoundation                      0x00007fff23b98958 +[NSException raise:format:arguments:] + 88
    3   Foundation                          0x00007fff255eb6f5 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 191
    4   UIKitCore                           0x00007fff468697ba -[_UISearchBarVisualProviderIOS prepareForTransitionToSearchLayoutState:] + 1306
    5   UIKitCore                           0x00007fff46869174 -[_UISearchBarVisualProviderIOS driveTransitionToSearchLayoutState:] + 180
    6   UIKitCore                           0x00007fff471c046a __68-[_UISearchControllerTransplantSearchBarAnimator animateTransition:]_block_invoke.98 + 107
    7   UIKitCore                           0x00007fff4762a1e6 +[UIView(UIViewAnimationWithBlocks) _setupAnimationWithDuration:delay:view:options:factory:animations:start:animationStateGenerator:completion:] + 528
    8   UIKitCore                           0x00007fff4762a795 +[UIView(UIViewAnimationWithBlocks) animateWithDuration:delay:options:animations:completion:] + 99
    9   UIKitCore                           0x00007fff471bfc15 -[_UISearchControllerTransplantSearchBarAnimator animateTransition:] + 862
    10  UIKitCore                           0x00007fff46b2c49e ___UIViewControllerTransitioningRunCustomTransition_block_invoke_2 + 54
    11  UIKitCore                           0x00007fff46c41ece +[UIInputResponderController _pinInputViewsForInputResponderController:onBehalfOfResponder:duringBlock:] + 99
    12  UIKitCore                           0x00007fff46b2c432 ___UIViewControllerTransitioningRunCustomTransition_block_invoke.645 + 180
    13  UIKitCore                           0x00007fff47628751 +[UIView(Animation) _setAlongsideAnimations:toRunByEndOfBlock:] + 175
    14  UIKitCore                           0x00007fff46b2c2b8 _UIViewControllerTransitioningRunCustomTransition + 553
    15  UIKitCore                           0x00007fff46a0fccb __56-[UIPresentationController runTransitionForCurrentState]_block_invoke.452 + 2632
    16  UIKitCore                           0x00007fff4716b85a _runAfterCACommitDeferredBlocks + 352
    17  UIKitCore                           0x00007fff4715c63c _cleanUpAfterCAFlushAndRunDeferredBlocks + 248
    18  UIKitCore                           0x00007fff4718bc6e _afterCACommitHandler + 85
    19  CoreFoundation                      0x00007fff23afaeb7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
    20  CoreFoundation                      0x00007fff23af594e __CFRunLoopDoObservers + 430
    21  CoreFoundation                      0x00007fff23af5fca __CFRunLoopRun + 1514
    22  CoreFoundation                      0x00007fff23af56b6 CFRunLoopRunSpecific + 438
    23  GraphicsServices                    0x00007fff3815cbb0 GSEventRunModal + 65
    24  UIKitCore                           0x00007fff47162a67 UIApplicationMain + 1621
    25  Properly                            0x000000010d3426d2 main + 80
    26  libdyld.dylib                       0x00007fff5123bcf5 start + 1
    27  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

最佳答案

简单的解决方案可以是点击一次后禁用取消按钮。然后执行其下的操作,当流程完成后,您可以根据需要启用它。

关于iOS 13 : Searchbar crashing when cancel is hit repeatedly,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58580129/

相关文章:

ios - UIButton 不显示图像

objective-c - -[UITableView layoutSublayersOfLayer :] 断言失败

ios - swift : 'attempt to delete row 0 from section 0 which only contains 0 rows before the update'

c# - IOS 中的 AES 解密没有给出确切的结果

iphone - - (CGRect)textRectForBounds :(CGRect)bounds limitedToNumberOfLines:(NSInteger)numberOfLines

ios - UISearchBar完全自定义背景

ios - 无法关闭 Popover UITableViewController

ios - 注册推送通知功能不会被调用

swift - 我如何在 Swift 4+ 中解析这个 GTFS 字符串

iphone - 使用 UISearchBar 关闭键盘,而不放弃第一响应者