Is it possible to perform a Popover Segue manually (from dynamic UITableView cell)?

后端 未结 4 849
隐瞒了意图╮
隐瞒了意图╮ 2020-12-14 01:09

I need to perform a Popover segue when user touches a cell in a dynamic TableView. But when I try to do this with this code:

- (void)tableView:(UITableView *         


        
4条回答
  •  伪装坚强ぢ
    2020-12-14 01:46

    I have made this in the simplest way:

    1. Make this Popover Presentation Segue in Storyboard as usually but drag from ViewController (not button)
    2. select anchor view as table view
    3. then in table view cell's button touch make:

       private func presentCleaningDateDatePicker(from button: UIButton) {
          performSegue(withIdentifier: "Date Picker Popover Segue", sender: button)
      }
      
    4. and implement prepare(for segue) method

        override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
      
          if let identifier = segue.identifier {
              switch identifier {
              case "Date Picker Popover Segue":
      
                  if let vc = segue.destination as? DatePickerViewController {
                      if let ppc = vc.popoverPresentationController {
                          ppc.sourceView = sender as! UIButton
                          ppc.sourceRect = (sender as! UIButton).frame
                          ppc.delegate = vc
      
                          vc.minimumDate = Date()
                          vc.maximumDate = Date().addMonth(n: 3)
                          vc.delegate = self
                      }
                  }
              default:
                  break
              }
          }
      }
      

提交回复
热议问题