Ios Swift---[\u UIAlertControlleratorPresentationController adaptivePresentationController]:发送到实例0x104fb1420的无法识别的选择器
我的应用程序在生产上崩溃了,我无法重现Fabric一直发送给我的错误。UISearchController有一些问题,但当我在应用程序上使用它时,效果很好。 我注意到的一件事是,在所有设备出现此错误时,可用的ram内存都很低。这可能与内存泄漏有关?由于需要更多内存,操作系统可能会解除分配对象,从而“无法识别的选择器发送到实例”,因为尝试发送消息(函数)的对象已经解除分配,但它是一个来宾,所以我仍然面临这个问题,在我的应用程序中,此时我没有任何内存泄漏 堆栈跟踪:Ios Swift---[\u UIAlertControlleratorPresentationController adaptivePresentationController]:发送到实例0x104fb1420的无法识别的选择器,ios,swift,crashlytics,uisearchcontroller,Ios,Swift,Crashlytics,Uisearchcontroller,我的应用程序在生产上崩溃了,我无法重现Fabric一直发送给我的错误。UISearchController有一些问题,但当我在应用程序上使用它时,效果很好。 我注意到的一件事是,在所有设备出现此错误时,可用的ram内存都很低。这可能与内存泄漏有关?由于需要更多内存,操作系统可能会解除分配对象,从而“无法识别的选择器发送到实例”,因为尝试发送消息(函数)的对象已经解除分配,但它是一个来宾,所以我仍然面临这个问题,在我的应用程序中,此时我没有任何内存泄漏 堆栈跟踪: Fatal Except
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)
}
无法识别的选择器
肯定不是内存泄漏。您在哪里显示警报(UIAlertController
)?是否有理由将searchController
声明为lazy
?我正在从UIViewController扩展中显示UIAlertController:func showartwith(标题:字符串,消息:字符串){let alert=UIAlertController(标题:标题,消息:消息,首选样式:。警报)让actionOk=UIAlertAction(标题:“Ok”,样式:。默认值,处理程序:{{in})警报。添加操作(actionOk)self.present(警报,动画:true,完成:nil)}
此外,如果网络请求出现问题,我会发出警报,但我的显示方式是在协议扩展实现中的函数上,并使用[weak self]引用ViewController,因为它处于ViewController持有的闭包中。我已用更多数据更新了我的问题