मैं UiTableView के लिए कार्रवाई को हटाने के लिए एक स्वाइप लागू कर रहा हूं, मैंने एक टेबल बनाया है जो ठीक काम करता है। लेकिन जब मैं किसी तालिका दृश्य में आइटम पर क्लिक करता हूं didSelectRowAt
को कॉल नहीं किया जाता है - यह लॉग में प्रिंट नहीं होता है।
कोड
class ManageUsersTable: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var editView: UIView!
@IBOutlet weak var main_user_table: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
editView.isHidden = true
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 6
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = Bundle.main.loadNibNamed("UsersTableCell", owner: self, options: nil)?.first as! UsersTableCell
cell.selectionStyle = UITableViewCellSelectionStyle.none
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print("selected : \(indexPath.row)")
}
func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
return true
}
func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
print("Delete at index : \(indexPath.row)")
let delete = UITableViewRowAction(style: .destructive, title: "Delete") { (action, indexPath) in
// delete item at indexPath
print("Delete at index : \(indexPath.row)")
self.editView.isHidden = false
}
// let edir = UITableViewRowAction(style: .normal, title: "Edit", icon : UIImage() ) { (action, indexPath) in
// print("Edit at index : \(indexPath.row)")
// }
// edit.backgroundColor = UIColor.darkGray
// return [delete, edit]
return [delete]
}
}
क्या कोई मुझे इस टीएनएक्स को ठीक करने में मदद कर सकता है।
अपडेट करें
जब मैं बाएं से दाएं स्वाइप करता हूं तो विधि काम करती है। आइटम क्लिक पर नहीं
2 जवाब
मुझे समाधान मिल गया
इसे अपने व्यूडिडलोड में करें
let tapOnScreen: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(ManageDevicestable.CheckTheTime))
tapOnScreen.cancelsTouchesInView = false
managetable.addGestureRecognizer(tapOnScreen)
चयनकर्ता जोड़ें विधि
func CheckTheTime() -> Void {
print("tapped")
}
निम्नलिखित सूची की जाँच करें।
1) UITableViewDelegate या UITableViewDataSource सेट करना न भूलें
2) कृपया अपना व्यूडिडलोड के साथ अपडेट करें
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
editView.isHidden = true
main_user_table.allowsMultipleSelectionDuringEditing = false //UPDATE THIS LINE
}
3) डिलीट स्वाइप का डिफ़ॉल्ट व्यवहार इस प्रकार है
A) जब आप सेल को स्वाइप करेंगे -> आपको एक डिलीट बटन दिखाई देगा।
इस फ़ंक्शन को कहा जाता है
func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
print("swipe")
return true
}
B) जब आप डिलीट बटन पर क्लिक करते हैं तो यह फंक्शन कहलाता है
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if(editingStyle == UITableViewCellEditingStyle.delete)
{
print("Delete Pressed")
}
}
ग) अब जब आपका डिलीट बटन दिखाई दे रहा है और फिर आप सेल पर टैप करते हैं न कि डिलीट बटन पर, तो डिलीट बटन छिप जाएगा और पहली बार किसी भी तरीके को कॉल नहीं किया जाएगा।
अब डिलीट बटन छिपा हुआ है और आप सेल को साधारण टैप करें। वहाँ तुम जाओ, अब आपके नीचे दिए गए फ़ंक्शन को कहा जाता है
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print("didSelectRowAt(\(indexPath)")
}
इसके अलावा यदि आप कोई अन्य व्यवहार चाहते हैं। फिर आपको UITableViewCell को अनुकूलित करना होगा।
यदि आप किसी अन्य समस्या का सामना कर रहे हैं तो कृपया अपने कार्यान्वयन को अच्छी तरह से दोबारा जांचें।
संबंधित सवाल
नए सवाल
ios
iOS, Apple iPhone, iPod टच और iPad पर चलने वाला मोबाइल ऑपरेटिंग सिस्टम है। IOS प्लेटफॉर्म पर प्रोग्रामिंग से संबंधित प्रश्नों के लिए इस टैग [ios] का उपयोग करें। उन प्रोग्रामिंग भाषाओं के लिए विशिष्ट मुद्दों के लिए संबंधित टैग [उद्देश्य-सी] और [स्विफ्ट] का उपयोग करें।