0

When I press the edit button located in the Header View nothing happens, the button is just not selectable and I'm not sure why.

The custom UICollectionReusableView with the edit UIButton and the button function.

class headerView: UICollectionReusableView {
var editProfile = UIButton()
func editBtnPressed(_ sender: UIButton) {

    let storyboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
    let vc : editVC = storyboard.instantiateViewController(withIdentifier: "search") as! editVC

    let navigationController =     UINavigationController(rootViewController: vc)

}


   override init(frame: CGRect) {
    super.init(frame: frame)


    addSubview(editProfile)

editProfile.translatesAutoresizingMaskIntoConstraints = false
  }
}

The UICollectionViewController that calls the edit UIButton function.

class homeVC: UICollectionViewController, UICollectionViewDelegateFlowLayout {

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

    //define header
    let header =    collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionElementKindSectionHeader, withReuseIdentifier: "Header", for: indexPath) as! headerView

    header.awakeFromNib()

    header.editBtn = editBtnPressed

    header.editProfile.addTarget(self, action: #selector(headerView.editBtnPressed(_:)), for: .touchUpInside)
  }
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579
Alex Cowley
  • 123
  • 4
  • 11

1 Answers1

0

You're calling awakeFromNib manually, but the system will be calling that automatically. I wouldn't be surprised if it being called twice would cause a weird issue like this. I'd try removing that manual call and see if that fixes it.

Also, you create editButton but don't set its frame anywhere. I'd also move your addSubview call out of init and into awakeFromNib when the view will be setup partially.

pmacro
  • 217
  • 2
  • 7