Reputation: 14904
i want to remove a button from a cell before reusing it. I am using:
func addImageToCell(image: UIImage, initialYCoordinate: CGFloat, initialHeight: CGFloat, initialXCoordinate: CGFloat) {
imageButton = UIButton.buttonWithType(UIButtonType.Custom) as? UIButton
....
self.contentView.addSubview(imageButton)
}
And to delete:
if let image = self.imageButton {
image.removeFromSuperview()
self.imageButton = nil
}
So, that works fine. But if there are more than one imageButtons, only the last one will be removed. I could use the same tag for each button, but i need the tag to identifer which imageButton is pressed.
I could also remove all buttons in subViews, but i have also other Buttons too which i dont want to delete.
Any ideas? Thanks in advance
Upvotes: 0
Views: 1000
Reputation: 559
After self.imageButton = nil
wrtie following line:
self.imageButton.removeFromSuperview()
i hope, these code works for you . . .
Upvotes: 1