Reputation: 951
Is there a way in code to add some hidden information to a UITableViewCell?
Use Case:
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
is called and each cell has one activity. Each its own unique "activityId".The code I have for the IBOutlet is:
- (IBAction)buttonUp:(UIButton *)sender {
UIButton *btn = (UIButton *) sender;
UITableViewCell *cell = (UITableViewCell *) [[btn superview] superview];
UIView *cellView = [cell.contentView viewWithTag: ..myUniqueButtonTag.. ];
NSLog(@"activityId is: %@", ...);
}
Upvotes: 0
Views: 333
Reputation: 119031
You shouldn't do the superview shuffle
: [[btn superview] superview]
because it will break sooner or later.
I agree with @ansible that you should create a custom cell and use a delegate relationship so the button tells the cell it is tapped and the cell tells the delegate. This is the best and most appropriate solution.
For cheaters though, consider using objc_setAssociatedObject
on the button to associate the id info with it so that you can access it in the action method.
Upvotes: 0
Reputation: 3579
Sounds like you need to create a custom UITableViewCell class if you want to do more complex things in your cells then the standard ones allow - https://developer.apple.com/library/ios/documentation/userexperience/conceptual/tableview_iphone/TableViewCells/TableViewCells.html
Upvotes: 6