0

Possible Duplicate:
How to access multiple buttons in access function?

I have two different buttons in the same cell in a TabelView (which has 10 rows each with 2 buttons) both set to 20% opacity. One called "button1" and the other "button2". When "button1" is clicked I run the action "button1clicked". In "button1clicked" I set the opacity of button1 to 50%. I need to set the opacity of button2 to 100%.

So I need to somehow be able to get a reference to button2 in the same cell as button1. I can get a reference to the cell via

UITableViewCell *clickedCell = (UITableViewCell *)[sender superview];

How can I use this or any other way so I can set the opacity of "button2" via something like

["somehow reference button2" setAlpha:.5];

Thank you!

Community
  • 1
  • 1
striff88
  • 97
  • 2
  • 10

3 Answers3

1

Your problem is that you seem to be violating MVC by overcomplicating your code. In the UITableViewCell subclass, make those buttons properties (if they aren't already), and implement the actions that set their opacity within the very same Table Cell class, no need for anything else. If you need to interact with other objects, make them delegates of the cell.

CodaFi
  • 43,043
  • 8
  • 107
  • 153
0

I would rather create a subclass of UIView as the content view of table view cell. Then you can handle the opacity change inside the UIView.

CarmeloS
  • 7,868
  • 8
  • 56
  • 103
0

I like the subclass solution, but the other traditional solution is to set the tag property for your two buttons you add to your cell and then you can retrieve later them via viewWithTag method.

Rob
  • 415,655
  • 72
  • 787
  • 1,044