Hi,
I have a tableView with sections for different OrderItemTypes, and in each row I have a swipe action to change type. What I'm trying to acheive is to reload the data after changing a type, so that the row changes section. As only necessary sections are created when the table is filled the first time, moving rows aren't a viable solution.
I have a tableview with a swipe action, which then calls an actionController. I'm trying to update the tableView after choosing an action from the action sheet, but I don't understand where to put the tableview.reloadData() call.
struct cartViewModel {
static func trailingSwipeActionsFor(_ item: orderItem, viewController: UITableViewController ) -> UISwipeActionsConfiguration? {
var actions = [UIContextualAction]()
let switchTypeAction = UIContextualAction(style: .normal, title: nil) { (_,_,success) in
let ac = UIAlertController(title: "Change type", message: nil, preferredStyle: .actionSheet)
for type in orderItem.orderItemType.allValues where type != item.type {
ac.addAction(UIAlertAction(title: "\(type.prettyName)", style: .default, handler: handleChangeType(item: item, type: type)))
}
ac.addAction(UIAlertAction(title: "Cancel", style: .cancel))
viewController.present(ac, animated: true)
success(true)
}
switchTypeAction.backgroundColor = UIColor.preferredFioriColor(forStyle: .accent10b)
nfigureAction.image = FUIIconLibrary.map.marker.job
actions.append(configureAction)
}
let swipeActions = UISwipeActionsConfiguration(actions: actions)
swipeActions.performsFirstActionWithFullSwipe = false
return swipeActions
}
static func handleChangeType(item: orderItem, type: orderItem.orderItemType) -> (_ alertAction:UIAlertAction) -> (){
return { alertAction in
item.type = type
}
}
I've tried to call it in "didEndEditingRowAt" and after call to "viewController.present(ac, animated: true)" (line 15 above), but none works. the call to present(ac, animated: true) seems also to be executed aync after "success(true)".