Ios 正在将数据从标头检索到父项';s观点

Ios 正在将数据从标头检索到父项';s观点,ios,swift3,delegates,swift-protocols,Ios,Swift3,Delegates,Swift Protocols,我有一个自定义的UICollectionViewController,带有自定义的标题和单元格 我已经实现了一个协议,collectionView会响应该协议,因此通过这种方式,我知道在collectionView中,当在header类中访问对象时(例如button press),到目前为止还不错 我想做的是,当我点击按钮时,在collectionView中,我需要标题来检索它拥有的一些数据到collectionView 假设我点击collectionView中的save按钮,为了执行save,

我有一个自定义的
UICollectionViewController
,带有自定义的标题和单元格

我已经实现了一个协议,collectionView会响应该协议,因此通过这种方式,我知道在collectionView中,当在header类中访问对象时(例如button press),到目前为止还不错

我想做的是,当我点击按钮时,在
collectionView
中,我需要标题来检索它拥有的一些数据到
collectionView

假设我点击
collectionView
中的save按钮,为了执行save,我需要标题中的当前数据

我怎样才能做到这一点

以下是一些当前代码:

    import UIKit

// collection view class
class EditUserProfileHeader: UICollectionViewCell, UITextViewDelegate {
    var delegate: CustomHeaderDelegate?

    //(... some default code ...)
    override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
        let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: headerId, for: indexPath) as! CustomHeader
        header.delegate = self
        return header
    }

    // header delegate conform
    func didTapPhoto() {
        // this fires everytime the button is pressed inside the header
        print("didTapPhoto was tapped inside the header")
    }


    func didTapSave() {
        //here I need the header's data from it's labels and so on
    }

}


protocol CustomHeaderDelegate {
    func didTapPhoto()
}



class CustomHeader: UICollectionViewCell { 
    var delegate: CustomHeaderDelegate?
    //(... some class regular code ...)

    func didTapPhoto() {
        delegate?.didTapPhoto() // here I pass to the collectionView that this button was pressed in the header
    }

}
如您所见,我已经实现了一个委托,每当标题中出现
didTapButton
时,我调用委托函数,以便在
collectionView
中知道按钮已触发

现在我需要尝试相反的方法;当我点击
collectionView
中的一个按钮时,我需要标题来了解它,并确保它检索到所需的数据

谁能帮我一下吗

我试图实现另一个协议来做相反的事情,但我可能做错了,因为它不起作用,主要是因为我不能在header类中“说”父代的委托符合该特定委托,当我实例化header对象并将其
委托设置为self


谢谢

在didTapSave()函数中插入以下行,我成功访问了所需的标题

let header = collectionView?.supplementaryView(forElementKind: UICollectionElementKindSectionHeader, at: IndexPath(item: 0, section: 0)) as? CustomHeader

因此,我可以访问标题更新的数据。

我通过在didTapSave()函数中插入以下行来访问所需的标题

let header = collectionView?.supplementaryView(forElementKind: UICollectionElementKindSectionHeader, at: IndexPath(item: 0, section: 0)) as? CustomHeader

因此,我可以访问标题更新的数据。

如果问题已解决,则将其标记为已解决。如果问题已解决,则将其标记为已解决。