I have a view with a table View. I has subclassed TableViewCells to make a representation of an object of my model. This Custom UITableViewCell has two buttons to change my object of the model(it makes +1 -1 to an instance variable).
So I think of how I should architecture all that, my options are:
-I put a pointer in the custom tableViewCell, when I receive a notification from one of the buttons I chance the cell and the object of the model(I don't like this solution because a View is changing my model, bad to reuse the cell so bad)
-Create a UICustomTableViewCellDelegate
protocol and an instance of id<UICustomTableViewCellDelegate>
in the cell class. When I receive a message from the UIElement I call my delegate. The delegate will point to the UIViewController of the general view who has an array with all the instances of my objects and here change the model. Before change the cell view to. I think is not bad for reuse but how I will identify and recover easily my object from the array of ViewController? I think the method should be:
-(void)customTableCellViewButtonPlusPressed:(CustomTableViewCell*) cell;
-Make a viewController for the CustomTableViewCell with a reference to my object. He will receive the message from the UIButtons of the cell and change the cellView and the object of the model referenced
What is the best practice?