I have a PFQueryTableViewController in which I am trying to learn some tableView interactions.
I currently have: a tableView cell increases its height on the didSelectRowAtIndexPath , or I can basically list the cell related data to the next viewController using performSegueWithIdentifier along with prepareForSegue with one click.
In the code below, if I comment out the code "Tap code to height height tableView cell", I can detect a double tap. Another wise single tap increases the height as the code inside is done. Select a block.
What I need: With a single press, the cell height increases or decreases. While the cell height increases, if I double-click it, it should pass the cell data to the next UIViewController .
If not, a single crane should increase or decrease the height. And the double tap should pass the cell data to the next UIViewController
The code is as follows:
var selectedCellIndexPath: NSIndexPath? var SelectedCellHeight = CGFloat() // currently set to 480.0 tableView height var UnselectedCellHeight = CGFloat() // currently set to 300.0 tableView unselected hight .... override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { if let selectedCellIndexPath = selectedCellIndexPath { if selectedCellIndexPath == indexPath { return SelectedCellHeight } } return UnselectedCellHeight } override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { var cell = tableView.dequeueReusableCellWithIdentifier("cell") as! DataViewTableViewCell! if cell == nil { cell = DataViewTableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "cell") } // Below is the double Tap gesture recognizer code in which // The single tap is working, double tap is quite difficult to get // as the cell height increases on single tap of the cell let doubleTap = UITapGestureRecognizer() doubleTap.numberOfTapsRequired = 2 doubleTap.numberOfTouchesRequired = 1 tableView.addGestureRecognizer(doubleTap) let singleTap = UITapGestureRecognizer() singleTap.numberOfTapsRequired = 1 singleTap.numberOfTouchesRequired = 1 singleTap.requireGestureRecognizerToFail(doubleTap) tableView.addGestureRecognizer(singleTap) // Tap code to increases height of tableView cell if let selectedCellIndexPath = selectedCellIndexPath { if selectedCellIndexPath == indexPath { self.selectedCellIndexPath = nil cell.postComment.fadeIn() cell.postCreatorPicture.alpha = 1 cell.postDate.fadeIn() // cell.postTime.fadeIn() cell.postCreator.fadeIn() } else { self.selectedCellIndexPath = indexPath } } else { selectedCellIndexPath = indexPath } tableView.beginUpdates() tableView.endUpdates() } func doubleTap() { print("Double Tap") } func singleTap() { print("Single Tap") }
In another way, I can make it work, if I can get the NSIndexPath selected cell outside the didSelectRowAtIndexPath code, I can basically double-click to execute, if necessary, to get the required action. Can you get NSIndexPath outside tables by default tableView?
source share