मेरे पास PFQueryTableViewController
है जिसमें मैं कुछ तालिका सीखने की कोशिश कर रहा हूं।दो क्रियाओं को करने के लिए UITableViewCell पर डबल और एकल टैप का पता लगाने
क्या मैं वर्तमान में है: tableView सेल एक नल didSelectRowAtIndexPath
पर इसकी ऊंचाई बढ़ जाती है या मैं मूल रूप से एक टैप का उपयोग कर एक साथ performSegueWithIdentifier
का उपयोग कर prepareForSegue
के साथ अगले ViewController करने के लिए सेल से संबंधित डेटा segue कर सकते हैं।
नीचे दिए गए कोड में, यदि मैं "तालिका दृश्य कक्ष की ऊंचाई बढ़ाने के लिए कोड टैप करें" कोड पर टिप्पणी करता हूं, तो मैं डबल टैप का पता लगा सकता हूं। अन्यथा एक ही टैप ऊंचाई बढ़ाता है क्योंकि कोड अंदर है ब्लॉक का चयन करें।
मुझे क्या चाहिए: एकल टैप पर, सेल ऊंचाई बढ़ जाती है या घट जाती है। जबकि सेल ऊंचाई बढ़ जाती है, अगर मैं दो बार टैप करता हूं, तो इसे सेल डेटा को 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")
}
अन्य तरह से मैं यह काम है कर सकते हैं, अगर मैं didSelectRowAtIndexPath
कोड के बाहर चयनित सेल की NSIndexPath
प्राप्त कर सकते हैं, मैं: और डबल टैप अगले UIViewController
संहिता के सेल डेटा रूप में नीचे है segue चाहिए यदि आवश्यक कार्रवाई प्राप्त करने के लिए और अधिक करने के लिए मूल रूप से डबल टैप का उपयोग कर सकते हैं। क्या आप तालिका के बाहर NSIndexPath
प्राप्त कर सकते हैं डिफ़ॉल्ट ब्लॉक देखें?
आप प्रतिनिधि के साथ आपको सेल ऑब्जेक्ट पास कर सकते हैं और इंडेक्सपैथ ढूंढ सकते हैं: एनएसआईएनएक्सएक्सपाथ * इंडेक्सपाथ = [self.tableView indexPathForCell: cell]; – Mohamad