Search code examples
iosobjective-cuitableviewcustom-cellaccessorytype

Set custom accessory type in cusom cell


I have a custom UITableViewCell, and I would like to add a custom accessory type to it. I can set the custom accessory type in the cellForRowAtIndexPath, but I don't think that is an ideal way.

Question: How can I set a custom accessory type to a custom cell?


Solution

  • You can just assign a custom UIView (image,button, etc..) to the property

    cell.accessoryView = <your custom view>;
    

    If the custom accessoryView is different in every cell the in the delegate method

    cellForRowAtIndexPath:
    

    you can create the assignment, if it is the same in each cell then you can subClass a UITableViewCell (follow this tutorial Link)