我有一个PFQueryTableViewController
我正在尝试学习一些tableView交互.
我目前拥有的:tableView单元格在水龙头上增加其高度,didSelectRowAtIndexPath
或者我基本上可以将单元格相关的数据performSegueWithIdentifier
与prepareForSegue
单个水龙头一起使用.
在下面的代码中,如果我评论"点击代码以增加tableView单元格的高度"代码,我可以检测到双击.其他方面,单击会增加高度,因为代码在didSelect块内.
我需要的:在单击时,细胞高度增加或减少.当细胞高度增加时,如果我双击,它应该将细胞数据分割到下一个UIViewController
.
如果没有,单击应增加或减少高度.并且双击应该将细胞数据分割到下一个UIViewController
代码如下:
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") }
我可以使其工作的另一种方式是,如果我可以NSIndexPath
在didSelectRowAtIndexPath
代码之外获得所选单元格,我基本上可以使用双击来执行if else以获得所需的操作.你可以NSIndexPath
到tableView默认块之外吗?