Reputation: 42167
I have a bunch of custom UITableCells that I have built in interface builder. These are then associated with their correct cell index and every looks great in my tableView.
Each cell has a few buttons, so rather than creating an outlet for each and every table cell button, is there a way to just "find" any UIButton types within the current cell? I need to do this because I want to give it an IBAction so when you click on the button it does something.
I am just wanting to save code, rather than creating 20 or more IBOutlets.
Ideas?
Upvotes: 0
Views: 1019
Reputation: 38606
I think you could iterate through the subviews
property in any UIView
, then to check if it's specifically a UIButton
you can use - (BOOL)isKindOfClass:(Class)aClass
. To differentiate between the UIButton
s you can apply tags to them or check other properties.
EDIT: By the way, why not just sub-class UITableViewCell, add your button(s) as IBOutlet properties, then when you want to access them you can just do myCell.someButton ? Here is an article on how to sub-class UITableViewCell and use it in your UITableView.
If you do it this way, then everything will be organized. The UITableView will only worry about its UITableViewCells, and each UITableViewCell will worry about its individual UIButtons.
Upvotes: 0
Reputation: 3380
If you give each a unique tag in Interface Builder, you can find them with the viewWithTag:
method of UIView
.
Upvotes: 2