-1

In my custom cell I have button which tagged in cellForRowAtIndexPath like this:

cell.downloadButton.tag = indexPath.row

By clicking on this button I want it to be hidden and another to be shown. How should I contact with specific cell knowing only tag of it's button?

SwiftStudier
  • 2,272
  • 5
  • 21
  • 43
  • More detail would be useful, what's the context? – The Beanstalk Aug 28 '15 at 19:10
  • the context that I have few buttons in custom cell and by clicking on first I want it to be hidden and another to be shown, so I dont know how to contacts to button I want to show – SwiftStudier Aug 28 '15 at 19:11
  • Posting the code for the custom cell would be helpful to see what you already have. – Individual11 Aug 28 '15 at 19:19
  • I have let a = sender.tag, (sender as! UIButton).hidden = true; was it helpful? – SwiftStudier Aug 28 '15 at 19:20
  • Post the whole class, or at least the function with that in it. – Individual11 Aug 28 '15 at 19:21
  • I updated my question for you guys, but it seems like you laugh at me. Which string was more helpful? "@IBAction" or function name? I told my problem on words. It does not need code support because problem is not in code – SwiftStudier Aug 28 '15 at 19:25
  • Not sure what you mean, but that code should work. You don't need the `let`, since you're not doing anything with it, and you can set your parameter to `UIButton` instead of `AnyObject` so you don't have to cast. That being said, I would add a `println("was pressed")` in there to make sure the function is being fired. If not, it's not connected to your button. – Individual11 Aug 28 '15 at 19:28
  • How. Should. I. Contact. To. Another. Button. Which. Is. Declared. As. downloadButton. To. Hide. Or. Show. It. I know that this code working and I saying again that I'm asking to for code fixing but for helping with new code string. Is it so hard to understand? – SwiftStudier Aug 28 '15 at 19:30

1 Answers1

1

Your question is hard to understand, the code you have appears to do what you're asking. Do you mean to ask how to get the cell that the button belongs to? If so inside downloadButtonClicked, you can get the cell it belongs to with sender.superview or sender.superview.superview and so on depending on how many superviews the button has. An example would look like this:

@IBAction func downloadButtonClicked(sender: AnyObject) {
    let cell = sender.superview.superview as! CustomTableViewCell
    cell.downloadButton.hidden = true
}
The Beanstalk
  • 798
  • 1
  • 5
  • 20