我有以下架构:
右上角的控制器是SelectAlbumVC
左下角的控制器是AddPhotoVC
在SelectAlbumVC中,我有以下代码:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
guard let destination = segue.destination as? AddPhotoPostVC
else { fatalError("unexpected view controller for segue") }
guard let cell = sender as? AlbumListCells else { fatalError("unexpected cell for segue") }
switch SegueIdentifier(rawValue: segue.identifier!)! {
case .showAllPhotos:
destination.fetchResult = allPhotos
destination.headerTitleBtnString = cell.allPhotoTitle.text!
case .showCollection:
// get the asset collection for the selected row
let indexPath = tableView.indexPath(for: cell)!
let collection: PHCollection
switch Section(rawValue: indexPath.section)! {
case .smartAlbums:
collection = smartAlbums.object(at: indexPath.row)
case .userCollections:
collection = userCollections.object(at: indexPath.row)
default: return // not reached; all photos section already handled by other segue
}
// configure the view controller with the asset collection
guard let assetCollection = collection as? PHAssetCollection
else { fatalError("expected asset collection") }
destination.fetchResult = PHAsset.fetchAssets(in: assetCollection, options: nil)
destination.assetCollection = assetCollection
destination.headerTitleBtnString = cell.collectionTitle.text!
destination.isComingFromSelectAlbum = true
}
}
所以基本上,当我点击一个单元格时,segue将被执行,数据将被传递给AddPhotoVC。
我的问题是,当segue被执行时,与SelectAlbumVC关联的导航控制器不会被解除,因此当单击AddPhotoVC SelectAlbumVC上的解除按钮时,将再次显示(它是堆栈中的最后一个控制器)。
当调用prepare for segue时,是否有方法关闭导航控制器?
我试着把下面的
self.navigationController?.popToRootViewController(animated: false)
但它不起作用。
任何帮助都将不胜感激。
谢谢您!
最佳答案
如果我正确地理解了你的代码,你将在AddPhotoVC中添加另一个segue。因此,如果在应用程序运行时,您单击了“调试视图层次结构”(在Xcode中由调试器控件向下),您将看到在原来的基础上有另一个AddPhotoVC。
与其执行从SelectPhotoVC到AddPhotoVC的segue,不如考虑改为执行展开segue。这样你就可以传递你想要的价值观,所有以前的风投都会被解雇。
关于ios - 准备好进行搜索后 swift 关闭导航 Controller ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46653299/