【发布时间】:2018-06-29 07:02:02
【问题描述】:
我有一个UICollectionViewCell(比如UICollectionViewCell 1),它有一个按钮,单元格内有UITextfields。连接到 (ViewController 1) 的 UICollectionViewCell 将 ViewController 1 推送到 detailedCollectionViewCell,即 (ViewController 2),该 ViewController 2 在单元格内还包含一个按钮和 UITextfields。
这是通过协议和委托完成的。我的问题,当点击第一个UICollectionViewCell (@987654336) 中的按钮时,我想将位于UICollectionViewCell (ViewController 1) 中的UITextfields 中的数据传递给detailedViewCell UITextfield (ViewController 2) @)。
这是我的代码:
//Protocol View Controller 1
protocol InfoCellDelegate: class {
func buttonToDetailCell()
}
// Inside ViewController 1 class
func buttonToDetailCell() {
let vc = InfoViewController(collectionViewLayout: UICollectionViewFlowLayout())
navigationController?.pushViewController(vc, animated: true)
}
// UICollectionViewCell
weak var delegate: InfoCellDelegate?
@objc func InfoButtonPressed(_ sender: UIButton) {
if cellOne.text != "" {
delegate?.buttonToDetailCell()
}
}
【问题讨论】:
标签: swift uicollectionviewcell viewcontroller pass-data