user8990288
user8990288

Reputation: 5

How can i add an action button into a collectionView's section cell?

I have a photos collection view with different section header with different items but i want to add an action button into the last cell of a section which will take a photo and will be added the photo to the section cell and only last cell of the section will be contain the action button .I attached a similar photos of screen in the link below.

Upvotes: 0

Views: 511

Answers (1)

CrazyPro007
CrazyPro007

Reputation: 1062

@User,

Add action(.touchUpInside) on button in header for all section and while performing events you can detect that if that section is last than perform task otherwise return.

e.g

Add these calls inside view for header in section

section.tempButton.tag = indexPath.section
section.tempButton.addTarget(self, action: #selector(performTask), for: .touchUpInside)

then it will call the selector when touched

@objc func performTask(sender:UIButton){
      if sender.tag == lastSection{
         //perform task  
      }
}

Upvotes: 1

Related Questions