Swift准备segue并解雇控制器

时间:2017-10-09 11:29:39

标签: ios swift uitableview uistoryboardsegue

我正在尝试在执行segue后使用导航控制器解除tableview控制器。

这是我的代码:

class SelectAlbum: UITableViewController {
..............
override func viewDidLoad() {
    super.viewDidLoad()
}

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    guard let destination = (segue.destination as? CustomNavigationBar)?.topViewController 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!
    }
}
........
}

问题是如果我在准备segue函数中解除控制器而不执行segue并且我在控制台日志中得到错误:"尝试出现....其视图不在窗口层次结构!"。

如何解除控制器并传递数据? 谢谢。

0 个答案:

没有答案