मेरा शीर्षक कहता है कि मैं UITableView
की पहली पंक्ति को बाएं से दाएं स्वाइप करना चाहता हूं जब उपयोगकर्ता ViewController
पर आएगा।स्पर्श के बिना UITableViewCell स्वाइप करें
मेरे ViewController
में मेरे पास एक UITableView
है, प्रत्येक पंक्ति में दो बटन "अधिक" और "हटाएं" कार्रवाई होती है। नीचे दिए गए कोड को देखें
func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
return true
}
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if (editingStyle == UITableViewCellEditingStyle.delete) {
}
}
func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
let deleteButton = UITableViewRowAction(style: .normal, title: "Delete") { action, index in
// Edit Button Action
}
deleteButton.backgroundColor = UIColor.red
let editButton = UITableViewRowAction(style: .normal, title: "Edit") { action, index in
// Delete Button Action
}
editButton.backgroundColor = UIColor.lightGray
return [deleteButton, editButton]
}
सभी अच्छे काम कर रहे हैं। लेकिन मैं चाहता हूं कि अंत उपयोगकर्ता इस ViewController
पर पहली बार आता है, इसलिए वे सूचित करेंगे कि स्वाइप कार्रवाई उपलब्ध है ताकि वे इसे निष्पादित कर सकें।
प्रश्न है: मैं पहली पंक्ति के लिए स्वचालित रूप से बाएं और दाएं स्वाइप कैसे कर सकता हूं?
मैंने क्या किया है?
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
let cell = posTblView.cellForRow(at: NSIndexPath(row: 0, section: 0) as IndexPath) as! POSUserTabelCell
UIView.animate(withDuration: 0.3, animations: {
cell.transform = CGAffineTransform.identity.translatedBy(x: -150, y: 0)
}) { (finished) in
UIView.animateKeyframes(withDuration: 0.3, delay: 0.25, options: [], animations: {
cell.transform = CGAffineTransform.identity
}, completion: { (finished) in
})
}
}
उपरोक्त कोड स्वाइप/चलती सेल काम कर रही है लेकिन "हटाएं" और "अधिक" बटन प्रदर्शित नहीं करती है।
तो कृपया मुझे सही दिशा में मार्गदर्शन करें।
आपका दृष्टिकोण बाएं और दाएं स्वाइप करने के लिए सही लगता है। हालांकि, मुझे यकीन नहीं है कि निर्मित बटनों को इस तरह हाइलाइट किया जा सकता है या नहीं। आप निश्चित रूप से क्या कर सकते हैं, 'UIView' को अपनी सामग्री के नीचे मूल नियंत्रण की तरह दिखाना है, उन्हें प्रकट करने के लिए स्वाइप करें, और उन्हें सेल से हटाएं/छुपाएं। यह उत्तर देखें: https://stackoverflow.com/questions/5301728/is-it-possible-to-programmatically-show-the-red-delete-button-on-a-uitableviewce – dirtydanee
आप इस पुराने ढांचे का उपयोग कर सकते हैं: https://github.com/CEWendel/SWTableViewCell। फिर दृश्यमान में लिखें: [सेल शोराइटयूटीलिटीबटन्सएनिएटेड: हाँ]; –
तो, आप क्या लक्ष्य रखते हैं कि पहली पंक्ति स्वचालित रूप से स्वाइप करें, ताकि आप संपादन बटन देख सकें। क्या वह सही है? –