Используйте UIView как MGSwipeButton - PullRequest
0 голосов
/ 30 августа 2018

У меня полностью рабочий tableView с ячейками, и я хотел бы настроить MGSwipeButton в соответствии с документами:

Использование этого класса не является обязательным, поскольку MGSwipeTableCell не зависит от кнопок и может использовать для этой цели любой UIView

У меня есть что-то вроде этого

class TurnOffAlarmSwipeButton: UIView {

  var callback: MGSwipeButtonCallback?

  override init(frame: CGRect){
    super.init(frame: frame)
    commonSetup()
  }

  required init?(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)
    commonSetup()
  }


  private func commonSetup() {    
    self.backgroundColor = .black
    self.callback = { cell -> Bool in
      print("ButtonTapped")
      return true
    }
  }

  @objc func handleTap(_ sender: UITapGestureRecognizer) {
    print("Button Clicked")
  }

}

И listController:

class ListController: UITableViewController, UISplitViewControllerDelegate,MGSwipeTableCellDelegate {
   ...


  func swipeTableCell(_ cell: MGSwipeTableCell, tappedButtonAt index: Int, direction: MGSwipeDirection, fromExpansion: Bool) -> Bool {
    print("Tapped as fck")
    return false
  }

  internal func getSwipeRightButtons(cell: MGSwipeTableCell) -> [UIView] {
    guard let indexPath = self.tableView.indexPath(for: cell) else {
      return []
    }

    let item = self.getItemByIndexPath(indexPath)

    let edit = MGSwipeButton(title: "ActiveAlarms_ContextMenu_DeactivateAlarm".localized(), icon: #imageLiteral(resourceName: "TurnOffAlarmIcon"), backgroundColor: UIColor.landaxColors.gray.dark, callback: { (cell) -> Bool in

      self.presentAlert(titleKey: "ActiveAlarmDeatils_PopUp_AlarmDeactivation_Title".localized(), messageKey: "ActiveAlarmDeatils_PopUp_AlarmDeactivation_Info".localized(), actions: [
        ("Alert_OkClose".localized(), nil),
        ("Alert_OkButton".localized(), { (action) in
          self.presentSimplePopover(message: "alarm for \n\n \(item.self) \n\n was activated? this dialog inform that we should get moved to activealarm details :) ")
        })
        ])

      return true
    })

    let customEdit = TurnOffAlarmSwipeButton()

    return [customEdit,edit]
  }
   ...
}

Одна кнопка правильно обрабатывается в методе func swipeTableCell(_ cell: MGSwipeTableCell, tappedButtonAt index: Int, direction: MGSwipeDirection, fromExpansion: Bool) -> Bool

Но этот тип UIView не работает с этой функцией. Есть идеи? Это вообще возможно? Эта кнопка действует как нажатие на ячейку (открыть детали)

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...