夫特辞退导航控制器,用于赛格瑞
后准备我有以下模式: 在右上角控制器是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
}
}
所以基本上当我点击一个单元格赛格将被执行和数据传递给AddPhotoVC。 我的问题是,执行segue时,与SelectAlbumVC关联的导航控制器不会被解除,因此再次显示单击AddPhotoVC SelectAlbumVC上的解除按钮时(它是堆栈中的最后一个控制器)。
有没有一种方法来解除导航控制器时准备for segue被调用? 我试着添加下方
self.navigationController?.popToRootViewController(animated: false)
,但它不工作。
任何帮助将非常感激。
谢谢!
如果我正确理解您的代码,您将添加另一个segue回到AddPhotoVC。因此,如果您的应用程序在运行时单击了“Debug View Hierarchy”(调试视图层次结构)(通过Xcode中的调试器控件),您会看到现在又有一个AddPhotoVC位于原始视图之上。
而不是执行从SelectPhotoVC到AddPhotoVC的segue,而是您可能需要考虑执行Unwind Segue。这样你可以传递你想要的值,所有以前的风险投资将被解雇。
您正在使用(多个)UINavigationController
。这意味着你是presenting
而不是pushing
它的第二个屏幕。
现在,你提到popToRootViewController
不起作用,那是因为两个屏幕又有两个不同的UINavigationController
。你应该dismiss
第二个屏幕,而不是popping
它,因为你提出了它。
了解推/显示和呈现viewControllers之间的差异。
Push/Show --- Pop。
目前---关闭。
而是这个self.navigationController?.popToRootViewController(animated: false)
使用此的:
self.navigationController?.dismiss(animated: true, completion: {
// completion, do something or make it nil.
})
,如果我打开 “调试视图层次” 我看到了一个NavivgationController和SelectAlbumVC内。不知道关于放松segue,因为我是新来的迅速,我从来没有见过他们,但如果这是唯一的解决方案,我会考虑它,并试图找出它... thx ... – Marco
@Marco如果你有这个项目的一个版本可以在GitHub上发布,我可以告诉你如何连接它。 – Causaelity
这里是链接... https://github.com/coty10/photo是照片部分的演示应用程序..谢谢!我真的很感激..我会研究它来更好地学习...... – Marco