TableKit icon indicating copy to clipboard operation
TableKit copied to clipboard

How to activate ability to delete a row?

Open wdcurry opened this issue 7 years ago • 14 comments

I am likely TableKit so far, but am used to more manual styles for setting up row deletion (and Parse). I find no examples of this within TableKit, only refs to .CanDelete but am not sure how to structure the code.

I am more interested in integrating Dwiff into TableKit but thought I should master this side first.

wdcurry avatar Feb 18 '19 21:02 wdcurry

Hi @wdcurry,

Here is an example of row deletion:

let row = TableRow<MyCell>(item: /*...*/)
            
let canDeleteAction = TableRowAction<MyCell>(.canDelete) { (options) in
    return true
}

let deleteAction = TableRowAction<MyCell>(.clickDelete) { [weak self] (options) in
    
    self?.tableDirector.sections[options.indexPath.section].delete(rowAt: options.indexPath.row)
    self?.tableView.beginUpdates()
    self?.tableView.deleteRows(at: [options.indexPath], with: .automatic)
    self?.tableView.endUpdates()
}

row.on(canDeleteAction)
row.on(deleteAction)

tableDirector += row

Hope it helps!

maxsokolov avatar Feb 18 '19 22:02 maxsokolov

This is awesome, thank you. I must have had a typo as I tried the original "return true" but received a compile error. Once I get tested, I will consider Dwiff as it is just so slick, as is TableKit.

wdcurry avatar Feb 18 '19 22:02 wdcurry

Perhaps my bits are not up-to-date, as I cannot assign a return value to canDeleteAction. This is what through me off the trail to begin with. The workflow is a bit unintuitive as the delete action in canDeleteAction is more an attribute than an action. Perhaps an evolution to allow us to pass in an array of attributes might make this tighter?

My pod line is: pod 'FileKit' and the laptop is new so I should have the latest. I trust my cell definition is not involved in the issue as it is only a T ..

edit: I had dropped a print() within the canDeleteAction closure and that was throwing it off, I can now proceed ;) to test.

wdcurry avatar Feb 18 '19 23:02 wdcurry

For completeness, as I typically work with arrays of records that feed my tables, I ended up with for video in self.recentVideos { rows.append( TableRow<RecentVideoTableViewCell>(item: video, actions: [action, canDeleteAction, deleteAction]) ) }. *yes, my formatting skills here suck at present ;)

wdcurry avatar Feb 18 '19 23:02 wdcurry

The workflow is a bit unintuitive as the delete action in canDeleteAction is more an attribute than an action.

The original idea behind all those actions is how UITableViewDelegate operates with that. Take a quick look at shouldHighlightRowAt/willSelectRowAt and all other methods. It's just one delegate and so many responsibilities...

At the moment of implementing I just followed simplicity and wrapped everything under Action kind of thing. Probably, it could have been done better by grouping actions some how, or even introduce some kind of Attributes. But I don't have such plans. It's good idea to document things better anyway.

maxsokolov avatar Feb 19 '19 13:02 maxsokolov

Thanks Max, you did a great job, and I like it. Once I get a bit of time, I will see about integrating Dwiff into the mix, which should allow even greater ease. The idea being that by simply managing the actual data itself will then be reflected into the tableview, which is a true plumber's helper.

wdcurry avatar Feb 19 '19 20:02 wdcurry

@maxsokolov Здравия желаю. Подскажи пожалуйста как изменять название "кнопки" удаления по свайпу с помощью TableKit ? Мне надо локализацию добавить

Majituteniyazov avatar Mar 26 '20 08:03 Majituteniyazov

@maxsokolov Здравия желаю. Подскажи пожалуйста как изменять название "кнопки" удаления по свайпу с помощью TableKit ? Мне надо локализацию добавить

@Majituteniyazov привет! Из коробки этой функции нет, придется наследоваться от TableDirector и добавить ему в наследнике реализацию метода. Чтобы управлять title можно будет реализовать кастомный action. См исходник как там реализованы методы data source и delegate.

maxsokolov avatar Mar 26 '20 18:03 maxsokolov

@maxsokolov хорошо, спасибо, постараюсь сделать

@maxsokolov Здравия желаю. Подскажи пожалуйста как изменять название "кнопки" удаления по свайпу с помощью TableKit ? Мне надо локализацию добавить

@Majituteniyazov привет! Из коробки этой функции нет, придется наследоваться от TableDirector и добавить ему в наследнике реализацию метода. Чтобы управлять title можно будет реализовать кастомный action. См исходник как там реализованы методы data source и delegate.

Majituteniyazov avatar Mar 27 '20 09:03 Majituteniyazov

@maxsokolov Приветствую! Мы уже как-то общались на тему кастомного тайтла выше. Подскажи можно ли как-либо кастомизировать TableRowAction ? Я хотел бы добавить туда пару других еще экшенов

Majituteniyazov avatar May 08 '20 05:05 Majituteniyazov

@maxsokolov Приветствую! Мы уже как-то общались на тему кастомного тайтла выше. Подскажи можно ли как-либо кастомизировать TableRowAction ? Я хотел бы добавить туда пару других еще экшенов

Не очень понимаю, что значит кастомизировать? Лучше рассмотреть на примере, что требуется сделать.

maxsokolov avatar May 08 '20 14:05 maxsokolov

@maxsokolov Приветствую! Мы уже как-то общались на тему кастомного тайтла выше. Подскажи можно ли как-либо кастомизировать TableRowAction ? Я хотел бы добавить туда пару других еще экшенов

Не очень понимаю, что значит кастомизировать? Лучше рассмотреть на примере, что требуется сделать.

Я хочу добавить TableRowActionType и реализацию (как пример: .on(.canDelete) и .on(clickDelete) ) я хочу добавить также .on(.editAction) и его реализацию

Majituteniyazov avatar May 13 '20 09:05 Majituteniyazov

Снимок экрана 2020-05-13 в 14 22 42

Majituteniyazov avatar May 13 '20 09:05 Majituteniyazov

Я хочу добавить TableRowActionType и реализацию (как пример: .on(.canDelete) и .on(clickDelete) )

Как вариант можно использовать .custom("")

invoke(action: .custom("my_action") ... )

.on(.custom("my_action") ... )

maxsokolov avatar May 13 '20 13:05 maxsokolov