Swift: Shinobi Grid show PopOver when selected


#1

I’m using Shinobi Data Grid with my Application. I want to show a simple popover when a row is selected. I try this code below but its not working :

          let cell = grid.visibleCell(atCoordinate: gridCoordinate)
    
  let popOver = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "option") as! OptionTableViewController
    
  popOver.modalPresentationStyle = .popover
   
  //      let selectedCellSourceView = tableView.cellForRow(at: indexPath)
  //      let selectedCellSourceRect = cell.bounds

//        let sourceView = grid.forBaselineLayout()
//        let sourceRect = grid?.layer.bounds
    
    popOver.popoverPresentationController?.delegate = self
    popOver.popoverPresentationController?.sourceView = sourceView
    popOver.popoverPresentationController?.sourceRect = sourceRect!
    popOver.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection.left
    

    popOver.preferredContentSize = CGSize(width: 320, height: 88)
    self.present(popOver, animated: true, completion: nil)

I have read this and this but none of one of the that reference using Swift. Any answer and suggest will help for me. Thanks in Advance.


#2

I try to search about creating PopOver manually and i solved with this code :

    var cell = grid.visibleCell(atCoordinate: gridCoordinate)
    
    let popOver = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "option") as! OptionTableViewController
    popOver.modalPresentationStyle = .popover
    
    var sourceView = grid.visibleCell(atCoordinate: gridCoordinate)
    var sourceRect = cell?.layer.bounds
    
    popOver.popoverPresentationController?.delegate = self
    popOver.popoverPresentationController?.sourceView = sourceView
    popOver.popoverPresentationController?.sourceRect = sourceRect!
    popOver.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection.any
    
    popOver.selectedRoomObjectData = self.selectedRoom
    
    popOver.preferredContentSize = CGSize(width: 320, height: 88)
    self.present(popOver, animated: true, completion: nil)

#3

Hi MrX,

I’m glad to hear you implementation a solution to your problem!

Thanks for contributing your answer to the forum.

It’s greatly appreciated.

Kind regards,
Andrew Polkinghorn.


#4

HI MrAPolk,

Thanks for appreciated, and I’m so glad too if my answer help someone :slight_smile:

Best regard,
Mario Margo Pradipta