When creating a custom UITableView cell I manually define a delegate variable in the @interface of a UITableViewCell class (each cell must communicate with parent class so the connection betweet two classes is needed). Then when a cell is attached to a UITableView, I just set that delegate variable.
@interface MyCellClass : UITableViewCell {
MyParentController *delegat;
}
@property (nonatomic, retain) MyParentController *delegat;
Is there a better way of doing it?
That could be ok but be sure you don’t make retain cycles. (A retains B, B retains A, none of them get never released)
If you are just using only a functionality of MyParentController then, it is a good idea to make a protocol and set a delegate as an object that adopts (implements) that @protocol, It is not mandatory but it is good practice and better design this way.
You could create your protocol like:
And Make your class:
Also, when you have delegates you should avoid making them retain or you will have retain cycles and hence, memory leaks.