2017-09-25 16 views
7

UITableViewDelegate.h में एक tableview कक्ष पर पूर्ण कड़ी चोट को निष्क्रियमैं कैसे करूँ iOS11

// Swipe actions 
// These methods supersede -editActionsForRowAtIndexPath: if implemented 
// return nil to get the default swipe actions 
- (nullable UISwipeActionsConfiguration *)tableView:(UITableView *)tableView leadingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(tvos); 
- (nullable UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(tvos); 

हालांकि, मैं अपने trailingActions विधि में शून्य लौट रहा हूँ और मैं अभी भी अपने tableview में हटाने के लिए एक पूर्ण कड़ी चोट कर सकते हैं। मैं पूरी स्वाइप कैसे रोक सकता हूं? (मैं उपयोगकर्ता चाहते हैं तो स्वाइप करने के लिए "हटाएँ" बटन दबाएँ करने के लिए

@available(iOS 11.0, *) 
func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? { 
    return nil 
} 

संपादित करें:।। मैं canEditRowAt लागू किया था और 9/स्विफ्ट 4 अद्यतन आईओएस 11/XCode से पहले संपादन शैली के लिए प्रतिबद्ध पूर्ण कड़ी चोट था सक्षम होने से पहले ही मैं trailingSwipeActionsConfigurationForRowAt कार्यान्वित

+0

क्या कोई कारण है कि आप क्रियाओं को संपादित करने के बजाय इस मामले के लिए स्वाइप क्रियाओं का उपयोग कर रहे हैं? संपादन आईओएस 8.0+ के बाद आईओएस 8.0+ के बाद उपलब्ध हैं, इसलिए उन डिवाइसों के लिए अधिक लचीलापन प्रदान किया जाएगा जिन्हें अभी तक हालिया आईओएस संस्करण में अपग्रेड नहीं किया गया है। मेरा मतलब यह एक स्पष्ट बिंदु के रूप में है, आपके प्रश्न का उत्तर नहीं। –

+0

मैं वास्तव में संपादन कार्यों का उपयोग कर रहा था। मैंने canEditRowAt लागू किया था और संपादन शैली को समर्पित किया था। लेकिन किसी कारण से (पीछे की प्रक्रिया को लागू करने से पहले SwipeActionsConfigurationForRowAt), पूर्ण स्वाइप सक्षम किया गया था। मैं इस प्रश्न को –

उत्तर

9

नीचे की तरह लागू:।

func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? { 
    let delete = UIContextualAction(style: .destructive, title: "Delete") { (action, sourceView, completionHandler) in 
     print("index path of delete: \(indexPath)") 
     completionHandler(true) 
    } 
    let swipeAction = UISwipeActionsConfiguration(actions: [delete]) 
    swipeAction.performsFirstActionWithFullSwipe = false // This is the line which disables full swipe 
    return swipeAction 
} 

इस लाइन जो पूर्ण कड़ी चोट को अक्षम करता है

swipeAction.performsFirstActionWithFullSwipe = false 

और यदि आप editingStyle और editActionsForRowAt जैसे किसी भी को लागू करते हैं तो अन्य कार्यों को हटा दें।

+0

शामिल करने के लिए अपना प्रश्न अपडेट कर रहा हूं, मेरे पास पहले संपादन संपादन स्टाइल फ़ंक्शन में कुछ तर्क था। क्या इसका मतलब है कि मैं उस तर्क को UIContextualAction के कोड ब्लॉक में स्थानांतरित कर सकता हूं? ऐसा लगता है, लेकिन मैं सोच रहा हूं कि यह सबसे अच्छा अभ्यास है या नहीं। –

+0

आपको इस तर्क को यहां स्थानांतरित करना होगा। –

संबंधित मुद्दे