John-Lluch / SWRevealTableViewCell

Highly configurable UITableViewCell subclass to display left and right buttons, similar to iOS8 mail app, based on user pan gestures or developer programmatic actions.
MIT License
425 stars 63 forks source link

Update SWCellButtonItem's image on tap #2

Open andreamazz opened 10 years ago

andreamazz commented 10 years ago

Hi First of all thanks for this library, it works just great. I was wondering if there's a way to change the SWCellButtonItem's image within the handler of the item. Something along this lines:

    SWCellButtonItem *item = [SWCellButtonItem itemWithImage:[UIImage imageNamed:@"on"] handler:^(SWCellButtonItem *item, SWRevealTableViewCell *cell) {
        item.image = [UIImage imageNamed:@"off"];
    }];

I need to do this since my image is a toggle associated with the cell. Is there any way to do so? Thanks

John-Lluch commented 10 years ago

I am not sure if I understand your requirement. The handler is called when you tap on the button item, but at this time you should dismiss the revealing cell, so I am not sure if you want to replace the image at this time. Can you be more specific about what visual behavior you would want? Thanks

andreamazz commented 10 years ago

I'm using the right buttons as flags to vote an item up or down. I don't want to dismiss the cell (so that the user can change his vote without swiping the cell away a second time), but provide a visual feedback of the user's action (by switching the outlined up/down icon with a 'full' icon).

andreamazz commented 10 years ago

This might help understanding what I mean: http://d.pr/i/yPfh (I currently implemented this with SWTableViewCell, but it breaks down with iOS8)

John-Lluch commented 10 years ago

Oh I see. I suppose this can be done by allowing setting item properties after they have been provided by the datasource. Currently, changing item properties only have an effect for the next revealing. I think UIBarITems update on screen by simply setting their image property, so I guess we could take a similar approach. Would that work?

andreamazz commented 10 years ago

Yep, that would be great! thanks

maddoggy1979 commented 10 years ago

:+1: for this enhancement - I am also keen to use this when it is available.