【发布时间】:2018-12-17 15:45:52
【问题描述】:
我有一个主视图控制器、一个容器视图和 2 个子视图控制器,我希望能够在子视图控制器之间切换(例如:当应用程序第一次加载时,我希望控制器包含要加载的 MapView,当我按下在主视图中找到的搜索栏时,带有要加载的表的控制器)。 这是我的故事板:https://i.stack.imgur.com/rDPMe.png
MainScreen.swift
class MainScreen: UIViewController {
@IBOutlet private weak var searchBar: UISearchBar!
@IBOutlet private weak var ContainerView: UIView!
//private var openSearchBar: Bool?
private var openMapView: Bool = true
private var openPlacesList: Bool = false
private var containerView: ContainerViewController!
override func viewDidLoad() {
super.viewDidLoad()
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
//let containerView = segue.destination as? ContainerViewController
if containerView == nil{
containerView = segue.destination as? ContainerViewController
}
if openMapView == true{
containerView!.moveToMapView()
}
else if openPlacesList == true{
containerView!.MoveToOpenPlaces()
}
}
}
//search bar delegate functions
extension MainScreen: UISearchBarDelegate{
//detects when text is entered
func searchBarTextDidBeginEditing(_ searchBar: UISearchBar) {
openPlacesList = true
openMapView = false
containerView!.MoveToOpenPlaces()
}
}
ContainerViewController.swift:
class ContainerViewController: UIViewController {
private var childViewController: UIViewController!
private var first: UIViewController?
private var sec: UIViewController?
override func viewDidLoad() {
super.viewDidLoad()
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "MainToMap"{
first = segue.destination as! MapViewController
self.addChild(first!)
self.view.addSubview(first!.view)
self.didMove(toParent: self)
}else{
sec = segue.destination as! PlacesListController
}
if(first != nil && sec != nil){
interchange(first!,sec!)
}
}
func interchange(_ oldVc: UIViewController,_ newVc: UIViewController ){
oldVc.willMove(toParent: nil)
self.addChild(newVc)
self.view.addSubview(newVc.view)
self.transition(from: oldVc, to: newVc, duration: 2, options: UIView.AnimationOptions.transitionCrossDissolve, animations: {
newVc.view.alpha = 1
oldVc.view.alpha = 0
}, completion: { (complete) in
oldVc.view.removeFromSuperview()
oldVc.removeFromParent()
newVc.willMove(toParent: self)
})
}
func moveToMapView(){
performSegue(withIdentifier: "MainToMap", sender: nil)
}
func MoveToOpenPlaces(){
performSegue(withIdentifier: "MainToSearches", sender: nil)
}
}
问题是当我按下搜索栏时,它会调用方法交换,然后它只会给出一个 SIGABRT 1 错误。我试过这个教程:https://developer.apple.com/library/archive/featuredarticles/ViewControllerPGforiPhoneOS/ImplementingaContainerViewController.html#//apple_ref/doc/uid/TP40007457-CH11-SW1 等等,但到目前为止还没有运气。我被困在这里,不知道如何解决这个问题。
堆栈:https://i.stack.imgur.com/Zqpm1.png SIGABR 1 错误:https://i.stack.imgur.com/NBgEN.png
【问题讨论】:
-
"那么它只会给出一个 SIGABRT 1 错误":当它发生时,您在控制台中是否有错误日志?如果是,你能分享它的内容吗?
-
嗨。它只是这样说:“libc++abi.dylib:以 NSException 类型的未捕获异常终止”。我还用堆栈添加了一张图片。
-
您能否复制/粘贴“libc++abi.dylib:以未捕获的 NSException 类型异常终止”的完整错误并用它编辑您的问题?
-
我怎样才能得到完整的错误?它只是这么说的。
-
上面什么都没有?
标签: ios swift uitableview mkmapview