我的应用程序正在崩溃生产,我无法重现Fabric不断发送给我的错误。 UISearchController存在一些问题,但是当我在应用程序上使用它时效果很好。 我注意到的一件事是在所有设备上出现此错误时可用的低RAM内存。它可能与内存泄漏有关吗?由于需要更多内存,操作系统可能会释放对象,从而将未识别的选择器发送到实例",因为尝试发送消息(函数)的对象已经解除分配,但是客户,我和#39;我仍然面临这个问题,在我的应用程序中,此时我没有任何内存泄漏。
堆栈跟踪:
Fatal Exception: NSInvalidArgumentException
-[_UIAlertControllerAlertPresentationController adaptivePresentationController]: unrecognized selector sent to instance 0x104fb1420
Raw Text
0
CoreFoundation
__exceptionPreprocess
1 libobjc.A.dylib
objc_exception_throw
2 CoreFoundation
__methodDescriptionForSelector
3
CoreFoundation
___forwarding___
4 CoreFoundation
_CF_forwarding_prep_0
5
UIKit
-[UISearchController _searchPresentationController]
6 UIKit
-[_UISearchControllerInPlaceSearchBarAnimator animateTransition:]
7 UIKit
__56-[UIPresentationController runTransitionForCurrentState]_block_invoke
8 UIKit
_runAfterCACommitDeferredBlocks
9 UIKit
_cleanUpAfterCAFlushAndRunDeferredBlocks
10 UIKit
_afterCACommitHandler
11 CoreFoundation
__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__
12 CoreFoundation
__CFRunLoopDoObservers
13 CoreFoundation
__CFRunLoopRun
14 CoreFoundation
CFRunLoopRunSpecific
15 GraphicsServices
GSEventRunModal
16
UIKit
UIApplicationMain
17 *****
MAMarketPlaceViewModel.swift line 14
main
18 libdyld.dylib
start
这就是我使用SearchController的方式:
lazy var searchController = { () -> UISearchController in
let search = UISearchController(searchResultsController: nil)
search.searchResultsUpdater = self
search.delegate = self
search.hidesNavigationBarDuringPresentation = false
search.dimsBackgroundDuringPresentation = false
search.definesPresentationContext = true
search.searchBar.placeholder = L10n.searchProducts
search.searchBar.delegate = self
return search
}()
....
fileprivate func setupNavigationBar() {
if #available(iOS 11.0, *) {
self.navigationController?.navigationBar.prefersLargeTitles = true
self.navigationItem.largeTitleDisplayMode = .always
self.navigationItem.searchController = searchController
self.navigationController?.navigationBar.tintColor = UIColor.Palette.intenseGray
self.navigationItem.hidesSearchBarWhenScrolling = false
} else {
self.extendedLayoutIncludesOpaqueBars = true
searchController.searchBar.searchBarStyle = .prominent
tableView.tableHeaderView = searchController.searchBar
}
if self.tableView.tableHeaderView != nil {
self.tableView.tableHeaderView?.isHidden = false
}
}
更新
在RxSwift的onError事件中我显示了AlertController,这是我认为我有一个UISearchController和一个显示AlertController的唯一地方。
protocol MarketCartPresentable : class {
var disposeBag : DisposeBag { get }
func showCart()
func present(product: MAProductMktPlace, with cart: MACarts)
}
extension MarketCartPresentable where Self : MAMainViewController, Self : MAMainViewControllerProtocol {
func showCart() {
guard let viewModel = self.viewModel as? Buyable else { return } //We need to have a ViewModel which impements Buyable Protocol! =)
viewModel.getCarts()
.asDriver(onErrorJustReturn: MACarts())
.asObservable()
.observeOn(MainScheduler.instance)
.subscribe(onNext: { [weak self](carts) in
let cartViewModel = MAMktCartViewModel(cartLines: carts)
let cartViewController = MAMktCartViewController(_associatedViewModel: cartViewModel)
let cartNavController = MACheckoutNavigationController(rootViewController: cartViewController)
self?.present(cartNavController, animated: true, completion: {
})
}, onError: { [weak self] (error) in
guard let errorMsg = error as? MAErrorProtocol else {
self?.showAlertWith(title: L10n.errorTitle , message: error.localizedDescription)
return
}
self?.showAlertWith(title: L10n.errorTitle , message: errorMsg.errorMessage)
}).addDisposableTo(self.disposeBag)
}