PFQueryTableViewController
tableView の相互作用を学習しようとしています。
私が現在持っているもの:tableViewセルはタップで高さを増やします。didSelectRowAtIndexPath
または、基本的にセル関連のデータを次のviewControllerにシングルタップperformSegueWithIdentifier
と一緒に使用できます。prepareForSegue
以下のコードで、「tableView セルの高さを増やすタップ コード」コードをコメントにすると、ダブルタップを検出できます。それ以外の場合は、コードが didSelect ブロック内にあるため、1 回のタップで高さが増加します。
必要なもの:シングルタップで、セルの高さが増減します。セルの高さが増加している間にダブルタップすると、セルデータが次のようにセグエされるはず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")
}
それを機能させるもう1つの方法は、コードNSIndexPath
の外で選択したセルを取得できる場合didSelectRowAtIndexPath
、基本的にダブルタップを使用して必要なアクションを取得することです。NSIndexPath
tableView のデフォルト ブロックの外に出ることができますか?