I have a UITableView with each cell containing the following
1) A UILabel (listing the names of people who clicked on the button)
2) A button (when clicked will add the clicker’s name to the list displayed in UILabel)
The button is an instance of a subclass of UIControl. So the intention is that when the button is clicked, I will add the current user to the array used by the UILabel for display.
However, I am unsure how I can reload the parent cell (in which the button is contained)
Just to re-iterate my issue
1) The addition of user name to list is done in the button subclass and not the UITableViewCell, how can I call the parent cell once I have updated the array?
2) I do not want to reload the entire table, just the specific cell in which the user has clicked the button.
Thanks in advance
Write an action method in the view controller which is the table view datasource, like :
Then in the
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;method, before returning the cell, configure it like so :This will make the
-(IBAction)reloadCell:(id)sender;method called when touching the button, and reloading the particular cell, but this solution will maybe make you move the code that updates the content of the list, as I don’t know which of the messages will be sent first (the one updates the content, or the one that reloads the cell).So the best way I think is, for your custom button subclass to have a weak reference to the controller, so the button could update the content, and then send a message to the controller, and is working based on the same action method in the controller.
In your button subclass .h
In your button subclass .m
Also don’t forget to configure correctly the cell