Reputation: 917
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?
Upvotes: 0
Views: 403
Reputation: 21221
Third solutions is the most mvc of them
UICustomTableViewCell
, this class will read the model and realize it on the view, it will also get the events from the view and change the model accordinglyUICustomTableViewCell
xib file, that will contain the information of the cell drawing and realizationthe model will be included inside UICustomTableViewCell in a "has a" relationship The UICustomViewCell class will be able to send drawing functions to the view and to receive events from the view and change the model accordingly
Upvotes: 1