标题collectionViewController中的tableViewController的Segue

时间:2017-07-09 17:57:16

标签: ios swift uitableview swift3 uicollectionview

请帮我处理我的代码,我是编程的新手,但我知道我的变量只需要一个零。而我无法解决的问题。 附:我的英语不好,但我学习。 :)

class ViewController: UITableViewController {

var file: File!

var files: [File] = [File(name: "name1", address: "address1", image: ""), File(name: "name2", address: "address2", image: "")]

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let dvc = segue.destination as? CollectionViewController {
    let indexPath = tableView.indexPathForSelectedRow?.row
    if indexPath == nil {
        dvc.files2 = files[indexPath!]
    } else {
        print("error")
    }
  }
}


class CollectionViewController: UICollectionViewController {

var files2: File!

override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {

let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "Header", for: indexPath) as! Header

header.nameLabel.text = files2!.name
header.addressLabel.text = "address"

return header
}

0 个答案:

没有答案