带有大标题的 UISearchController 在 "Only one palette with a top boundary edge can be active outside of a transition" 的标签栏中崩溃
UISearchController with large titles crashes in Tab bar with "Only one palette with a top boundary edge can be active outside of a transition"
我在 UITabBarController 中有多个选项卡。它们都有一个带有大标题的 UINavigationBar 和一个 iOS-11-built-in-search-bar。但是,在选项卡之间切换会使应用程序崩溃
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:
'Only one palette with a top boundary edge can be active outside of a transition. Current active palette is
<_UINavigationControllerManagedSearchPalette: 0x7fc399b49980; frame = (0 96; 375 52); layer = <CALayer: 0x60c0004383a0>>'
我已经测试了此处发布的解决方法: 但没有成功。本题没有使用UITabBarController。
我已将此代码添加到 viewDidAppear
:
DispatchQueue.main.async {
let searchController = UISearchController(searchResultsController: nil)
searchController.searchResultsUpdater = self
self.navigationItem.searchController = searchController
}
这对 viewWillDisappear
:
self.navigationItem.searchController = nil
向每个方法添加打印以检查顺序,以验证在将其设置在出现的视图之前是否将前一个视图清零。
从选项卡 0 转到选项卡 1,然后返回选项卡 0 后崩溃。我什至不需要向下滚动来显示搜索栏。
完整堆栈跟踪:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Only one palette with a top boundary edge can be active outside of a transition. Current active palette is <_UINavigationControllerManagedSearchPalette: 0x7fea7dcaf880; frame = (0 44; 375 52); layer = <CALayer: 0x60000062ac20>>'
*** First throw call stack:
(
0 CoreFoundation 0x000000010b8381e6 __exceptionPreprocess + 294
1 libobjc.A.dylib 0x0000000109cda031 objc_exception_throw + 48
2 CoreFoundation 0x000000010b8ad975 +[NSException raise:format:] + 197
3 UIKit 0x000000010e67dec6 -[UINavigationController(_UIPalette) attachPalette:isPinned:] + 521
4 UIKit 0x000000010e659afd -[UINavigationController _createAndAttachSearchPaletteForTopViewControllerIfNecessary:] + 585
5 UIKit 0x000000010e677c10 -[UINavigationController _navigationItemDidUpdateSearchController:oldSearchController:] + 419
6 UIKit 0x000000010f0737a1 -[_UINavigationBarVisualProviderModernIOS navigationItemUpdatedSearchController:oldSearchController:animated:] + 160
7 UIKit 0x000000010edf15c4 -[UINavigationItem setSearchController:] + 135
8 Appmost 0x0000000107e5902e _T07Appmost25JsonCreatedViewControllerC14setupSearchBaryyFyycfU_ + 1486
9 Appmost 0x0000000107e590cd _T07Appmost25JsonCreatedViewControllerC14setupSearchBaryyFyycfU_TA + 13
10 Appmost 0x0000000107cbcb7d _T0Ieg_IeyB_TR + 45
11 libdispatch.dylib 0x00000001124c97ab _dispatch_call_block_and_release + 12
12 libdispatch.dylib 0x00000001124ca7ec _dispatch_client_callout + 8
13 libdispatch.dylib 0x00000001124d58cf _dispatch_main_queue_callback_4CF + 628
14 CoreFoundation 0x000000010b7fac99 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
15 CoreFoundation 0x000000010b7beea6 __CFRunLoopRun + 2342
16 CoreFoundation 0x000000010b7be30b CFRunLoopRunSpecific + 635
17 GraphicsServices 0x0000000113adaa73 GSEventRunModal + 62
18 UIKit 0x000000010e482057 UIApplicationMain + 159
19 Appmost 0x0000000107f72167 main + 55
20 libdyld.dylib 0x0000000112547955 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSExceptio
我已经在 viewDidLoad() 中添加了这段代码,它正在运行
尝试添加这行代码:
searchController.dimsBackgroundDuringPresentation
我试图重现问题,但当我在 func viewDidLoad()
中添加代码时一切似乎都很好
下面是在iOS11
中添加搜索视图控制器的代码
if #available(iOS 11.0, *) {
//Setup Search Controller
self.searchController.obscuresBackgroundDuringPresentation = false
self.searchController.searchBar.placeholder = "Search"
self.searchController.searchBar.barStyle = .black
self.searchController.searchBar.delegate = self
self.definesPresentationContext = true
self.navigationItem.searchController = searchController
self.navigationItem.title = "Heading 2"
}
我还为您创建了一个演示项目,请在Github Here
中找到它
这些行解决了我的问题。
let search = UISearchController(searchResultsController: nil)
search.obscuresBackgroundDuringPresentation = false
self.definesPresentationContext = true
我在 UITabBarController 中有多个选项卡。它们都有一个带有大标题的 UINavigationBar 和一个 iOS-11-built-in-search-bar。但是,在选项卡之间切换会使应用程序崩溃
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:
'Only one palette with a top boundary edge can be active outside of a transition. Current active palette is
<_UINavigationControllerManagedSearchPalette: 0x7fc399b49980; frame = (0 96; 375 52); layer = <CALayer: 0x60c0004383a0>>'
我已经测试了此处发布的解决方法:
我已将此代码添加到 viewDidAppear
:
DispatchQueue.main.async {
let searchController = UISearchController(searchResultsController: nil)
searchController.searchResultsUpdater = self
self.navigationItem.searchController = searchController
}
这对 viewWillDisappear
:
self.navigationItem.searchController = nil
向每个方法添加打印以检查顺序,以验证在将其设置在出现的视图之前是否将前一个视图清零。
从选项卡 0 转到选项卡 1,然后返回选项卡 0 后崩溃。我什至不需要向下滚动来显示搜索栏。
完整堆栈跟踪:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Only one palette with a top boundary edge can be active outside of a transition. Current active palette is <_UINavigationControllerManagedSearchPalette: 0x7fea7dcaf880; frame = (0 44; 375 52); layer = <CALayer: 0x60000062ac20>>'
*** First throw call stack:
(
0 CoreFoundation 0x000000010b8381e6 __exceptionPreprocess + 294
1 libobjc.A.dylib 0x0000000109cda031 objc_exception_throw + 48
2 CoreFoundation 0x000000010b8ad975 +[NSException raise:format:] + 197
3 UIKit 0x000000010e67dec6 -[UINavigationController(_UIPalette) attachPalette:isPinned:] + 521
4 UIKit 0x000000010e659afd -[UINavigationController _createAndAttachSearchPaletteForTopViewControllerIfNecessary:] + 585
5 UIKit 0x000000010e677c10 -[UINavigationController _navigationItemDidUpdateSearchController:oldSearchController:] + 419
6 UIKit 0x000000010f0737a1 -[_UINavigationBarVisualProviderModernIOS navigationItemUpdatedSearchController:oldSearchController:animated:] + 160
7 UIKit 0x000000010edf15c4 -[UINavigationItem setSearchController:] + 135
8 Appmost 0x0000000107e5902e _T07Appmost25JsonCreatedViewControllerC14setupSearchBaryyFyycfU_ + 1486
9 Appmost 0x0000000107e590cd _T07Appmost25JsonCreatedViewControllerC14setupSearchBaryyFyycfU_TA + 13
10 Appmost 0x0000000107cbcb7d _T0Ieg_IeyB_TR + 45
11 libdispatch.dylib 0x00000001124c97ab _dispatch_call_block_and_release + 12
12 libdispatch.dylib 0x00000001124ca7ec _dispatch_client_callout + 8
13 libdispatch.dylib 0x00000001124d58cf _dispatch_main_queue_callback_4CF + 628
14 CoreFoundation 0x000000010b7fac99 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
15 CoreFoundation 0x000000010b7beea6 __CFRunLoopRun + 2342
16 CoreFoundation 0x000000010b7be30b CFRunLoopRunSpecific + 635
17 GraphicsServices 0x0000000113adaa73 GSEventRunModal + 62
18 UIKit 0x000000010e482057 UIApplicationMain + 159
19 Appmost 0x0000000107f72167 main + 55
20 libdyld.dylib 0x0000000112547955 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSExceptio
我已经在 viewDidLoad() 中添加了这段代码,它正在运行
尝试添加这行代码:
searchController.dimsBackgroundDuringPresentation
我试图重现问题,但当我在 func viewDidLoad()
下面是在iOS11
中添加搜索视图控制器的代码 if #available(iOS 11.0, *) {
//Setup Search Controller
self.searchController.obscuresBackgroundDuringPresentation = false
self.searchController.searchBar.placeholder = "Search"
self.searchController.searchBar.barStyle = .black
self.searchController.searchBar.delegate = self
self.definesPresentationContext = true
self.navigationItem.searchController = searchController
self.navigationItem.title = "Heading 2"
}
我还为您创建了一个演示项目,请在Github Here
中找到它这些行解决了我的问题。
let search = UISearchController(searchResultsController: nil)
search.obscuresBackgroundDuringPresentation = false
self.definesPresentationContext = true