Passing a boolvalue from a UITableViewCell to the parent UITableViewController then remove the cell based on the boolvalue

My TableView loads the tableView, it's DataSource is from a remote JSON that is serialized. The TableView creates the number of cells necessary from the count of the array. Then, the TableView loads the Cells...the Cell has it's own class subclassed as a UITableViewCell. So the Cell and TableView both have completely different classes.


So, now to the question:

The cell sends an ICMP ping to a machine. If the ping is successful, I want the cell removed from the TableView with no user interaction.

How can this be done?

Replies

Read the documentation for UITableView, especially the bit about deleteRowsAtIndexPaths:withRowAnimation:

THank you for your response, however..I have. And what the documentation does not state is updating the dataSource of the TableView from a dependancy of an If statement in a cell that has it's own subclass of UITableViewCell.

But when you get back your ping can't you just remove the particular entry from the relevant array and then just do a [self.tableView reloadData]? Is your question then how do you initiate those activities in a different class? If so, use NSNotifications.

It sounds like you are putting too much logic in the individual cells. Optimally, the cells should just be views, with no knowledge other than that they can display provided information. Your view controller would handle interation between the view and the model. The model would call the server and then let the view controller know of the change, which would then update the views (in this case just reload the table view).

That said, if you can't/won't change your setup, one way would be to add a delegate to each cell, assign the delegates to the view controller that manages the table view, remove the given cell data from the array when the delegate is called, and reload the tableview.