Jacob Kranz
Jacob Kranz

Reputation: 951

add hidden information to UITableViewCell

Is there a way in code to add some hidden information to a UITableViewCell?

Use Case:

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

Answers (2)

Wain
Wain

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

ansible
ansible

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

Related Questions