romaonthego / RETableViewManager

Powerful data driven content manager for UITableView.
MIT License
2.48k stars 430 forks source link

Easy way to change the Apple cell style #16

Closed KrauseFx closed 11 years ago

KrauseFx commented 11 years ago

I wanted to set the cell style of my cells (e.g. UITableViewCellStyleValue1, UITableViewCellStyleValue2)

As far as I found out the only easy way to do that is to subclass ReTableViewItem, override the initializer and set the style there.

- (id)initWithTitle:(NSString *)title
      accessoryType:(UITableViewCellAccessoryType)accessoryType
   selectionHandler:(void (^)(RETableViewItem *))selectionHandler
accessoryButtonTapHandler:(void (^)(RETableViewItem *))accessoryButtonTapHandler
{
    if ((self = [super initWithTitle:title
                                    accessoryType:accessoryType
                                 selectionHandler:selectionHandler
           accessoryButtonTapHandler:accessoryButtonTapHandler])) {
        self.style = UITableViewCellStyleValue1;
    }
    return self;
}

Wouldn't it be better to set it like this from outside without the requirement to subclass:

[GCTournamentItem setDefaultCellStyle:UITableViewCellStyleValue1];

What do you think?

KrauseFx commented 11 years ago

I can implement this feature if you want. Just wanted to ask first, to be sure I'm not missing something obvious.

romaonthego commented 11 years ago

I don't think it's a good idea to mass assign cell style on a class level. In most of the cases the cell style will depend on a particular item and its attributes. Each item has the style property:

RETableViewItem *item = [RETableViewItem item];
item.style = UITableViewCellStyleValue1;
KrauseFx commented 11 years ago

Let's say I have a GCAppointmentItem class which represents an appointment. Every time I present an appointment I want to display the title and the name. I'd have to set the style manually every time I create a GCAppointMentItem (when I don't want to override the initializer), instead of setting it once as default. Does that make sense?

romaonthego commented 11 years ago

Right, so in your subclass' initializer override the style, that seems logical to me. This is your edge case, there's a possibility of a million edge cases where people would want to define, say, custom text color for each cell type, etc. I have the main goal of keeping it simple by getting rid of UITableViewDelegate burden.