2017-02-05 1 views
0

Первый раз, пытаясь реализовать меню. У меня есть обычай UITableViewCell, используемый в UITableView в UITableViewController. TableView настраивается следующим образом:shouldShowMenuForRowAt не называется

fileprivate configureTableView() { 
    tableView.register(UINib(nibName: TransactionTableViewCell.nibName, bundle: nil), forCellReuseIdentifier: TransactionTableViewCell.identifier) 
    tableView.rowHeight = UITableViewAutomaticDimension 
    tableView.estimatedRowHeight = TransactionEntryTableViewCell.defaultHeight 
} 

Я создаю ячейку ниже примерно так:

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
    switch indexPath.section { 
    case 0: 
     guard let cell = tableView.dequeueReusableCell(withIdentifier: TransactionTableViewCell.identifier, for: indexPath) as? TransactionTableViewCell else { DLog("ERROR getting TransactionTableViewCell"); return UITableViewCell() } 
     let entry = entries[indexPath.row] 
     cell.entry = entry 
     return cell 

    case 1: 
     let cell = tableView.dequeueReusableCell(withIdentifier: "newTransactionCell", for: indexPath) 
     cell.textLabel?.text = Strings.AddANewTransaction 
     return cell 

    default: 
     assert(false) 
     return UITableViewCell() 
    } 

методы, связанные с меню заключаются в следующем:

override func tableView(_ tableView: UITableView, shouldShowMenuForRowAt indexPath: IndexPath) -> Bool { 
    print("shouldShowMenuForRowAt") 
    return true 
} 

override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool { 
    print("canPerformAction") 
    return action == MenuAction.duplicate.selector() 
} 

override func tableView(_ tableView: UITableView, performAction action: Selector, forRowAt indexPath: IndexPath, withSender sender: Any?) { 
    print("action = \(action)") 
} 

Все, кажется, работает нормально; однако метод shouldShowMenuForRowAt не вызывается при длительном нажатии на таблицу.

У меня есть пример проекта, который отлично работает. Однако это не работает. Какие идеи могут быть причиной?

ответ

0

Вы должны переопределить метод UITableViewDelegate вместо NSObject:

override func tableView(_ tableView: UITableView, canPerformAction action: Selector, forRowAt indexPath: IndexPath, withSender sender: Any?) -> Bool { 
    return action == MenuAction.duplicate.selector() 
} 
Смежные вопросы