Search code examples
swiftuitableviewswiftcharts

SwiftCharts StackBars in TableViewCell difficult to tap


I have created a calendar app which uses SwiftCharts to display a time bar like this: enter image description here

I nest the chart bars inside UITableViewCells. When I tap on the cells (not the event bar directly), I navigate to another view. Everything currently works great except when I tap directly on the bars themselves. It seems like there is a tapGestureRecognizer or something on the bars that is overriding the cell tap. Currently when i tap the bar the stackFrameSelectionViewUpdater runs, which changes the opacity of the bar, however, the print statement never runs. Id like to either disable to tapRecognizer on the bar or have the tap trigger the segue. Any idea how I might do either?

here is my current code:

barStack = ChartStackedBarsLayer(xAxis: xAxis,
                             yAxis: yAxis,
                             innerFrame: innerFrame,
                             barModels: allDayEventBar,
                             horizontal: true,
                             barWidth: 500,
                             settings: chartviewSettings,
                             stackFrameSelectionViewUpdater: ChartViewSelectorAlpha(selectedAlpha: 1, deselectedAlpha: 0.75),
                            tapHandler: {tappedBar in
                                print("user tapped bar")
                                //run segue
                            })

Heres the github post about the issue: StackBars in TableViewCell difficult to tap


Solution

  • This may be caused by a layering issue unknowingly that I created by instantiating the chart in a different ViewController, then appending it to a view inside a parent ViewController. Although I never solved it a found a decent work around with a long tap gesture recognizer like this:

    let longPressGesture:UILongPressGestureRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(self.handleLongPress(_:)))
    longPressGesture.minimumPressDuration = 0.3 
    longPressGesture.delegate = self
    self.usersTableVew.addGestureRecognizer(longPressGesture)
    
     func  handleLongPress(_ longPressGestureRecognizer: UILongPressGestureRecognizer) {
            if longPressGestureRecognizer.state == UIGestureRecognizerState.began {
                let touchPoint = longPressGestureRecognizer.location(in: self.view)
                if let indexPath = self.usersTableVew.indexPathForRow(at: touchPoint) {
                    let cellData = self.homeTableData[indexPath.section][indexPath.row]
                    GlobalNavDelegate.homeVCDelegate!.selectedName = cellData.name
                    GlobalNavDelegate.homeVCDelegate!.segueToEditPersonCal()
                }
            }
        }
    

    Check out the github post if your curious about it