मैं डिलीट बटन दिखाए बिना एनीमेशन के सेल को मिटाने के लिए टेबल व्यू सेल में कहीं भी बाएं या दाएं स्वाइप करने में सक्षम होना चाहता हूं। मैं यह कैसे कर सकता हूँ?कोई हटाए गए बटन वाले सेल को हटाने के लिए UITableViewCell में कहीं भी बाएं या दाएं स्वाइप करें?
उत्तर
मैंने इसे आजमाया और कार्यान्वित नहीं किया है, लेकिन मैं इसे एक शॉट दूंगा। सबसे पहले, एक कस्टम UITableViewCell
- एक संदर्भ का उपयोग कर सकते उस में किया जा रहा है डालते हैं। TableView में सेल खोजने के लिए। (जब भी आप सभी कक्षों के लिए सेल हटाते हैं, तो इसे अपडेट करने की आवश्यकता होती है)
अपने cellForRowAtIndexPath:
में, जहां आप कस्टम सेल बनाते हैं, इन गुणों को सेट करें। इसके अलावा सेल
cell.tableView=tableView;
cell.indexPath=indexPath;
UISwipeGestureRecognizer *swipeGestureRecognizer=[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(deleteCell:)];
[cell addGestureRecognizer:swipeGestureRecognizer];
[swipeGestureRecognizer release];
सुनिश्चित करें कि इशारा केवल क्षैतिज स्वाइप प्राप्त करता है बनाने के लिए एक UISwipeGestureRecognizer जोड़ें।
-(BOOL) gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
if([[gestureRecognizer view] isKindOfClass:[UITableViewCell class]]&&
((UISwipeGestureRecognizer*)gestureRecognizer.direction==UISwipeGestureRecognizerDirectionLeft
||(UISwipeGestureRecognizer*)gestureRecognizer.direction==UISwipeGestureRecognizerDirectionRight)) return YES;
}
अपने deleteCell:
-(void) deleteCell:(UIGestureRecognizer*)gestureRec
{
UIGestureRecognizer *swipeGestureRecognizer=(UISwipeGestureRecognizer*)gestureRec;
CustomCell *cell=[swipeGestureRecognizer view];
UITableView *tableView=cell.tableView;
NSIndexPath *indexPath=cell.indexPath;
//you can now use these two to perform delete operation
}
भूलें कि आपको इशारा पहचानकर्ता के लिए दिशा निर्धारित करने की आवश्यकता है जब इसे सेल में जोड़ने के लिए पहली बार शुरू किया जाए। ऐसा कुछ: swipeGestureRecognizer.direction = UISwipeGestureRecognizerDirectionRight; – ColossalChris
ऐप्पल, आपको '(शून्य) रद्द करने के लिए नाराज हैप्रतिफॉर्मफॉर्मफॉर्म्सथिथ लक्ष्य: (आईडी) एक लक्ष्य चयनकर्ता: (एसईएल) एक चयनकर्ता'। –
इसके लिए आपको अपनी परियोजना में यह कोड जोड़ना होगा।
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
// Return YES if you want the specified item to be editable.
return YES;
}
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
//add code here for when you hit delete
}
}
वरना मोर की जानकारी यू इस लिंक के माध्यम से जा सकते हैं enter link description here
विवेक2012 और आईविल - आपके उत्तर के लिए धन्यवाद लेकिन मैं एक डिलीट बटन नहीं दिखाना चाहता हूं, स्टैक ओवरफ्लो में पहले से ही उत्तर हैं। मैं चाहता हूं कि सेल को उस समय से मिटा दिया जाए जब उसे स्वाइप बाएं या दाएं इशारे मिल जाए।कृपया मेरा विवरण पढ़ें – carbonr
,
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath;
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath;
इन दोनों तरीकों को लागू करता है, तो UITableViewCellEditingStyle UITableViewCellEditingStyleDelete है, तो कर sth
साथ अपने सेल को मिटाने के लिए- (void)deleteRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;
यह सब कुछ है।
समाधान @MadhavanRP द्वारा पोस्ट की में काम करता है, लेकिन यह अधिक जटिल की तुलना में यह करने की जरूरत है। आप एक सरल दृष्टिकोण ले सकते हैं और एक इशारा पहचानकर्ता बना सकते हैं जो तालिका में होने वाली सभी स्वाइप को संभालता है, और उसके बाद यह निर्धारित करने के लिए स्वाइप का स्थान प्राप्त करें कि उपयोगकर्ता किस सेल को स्वाइप करता है।
सेट करने के लिएइशारा पहचानकर्ता:
- (void)setUpLeftSwipe {
UISwipeGestureRecognizer *recognizer;
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self
action:@selector(swipeLeft:)];
[recognizer setDirection:UISwipeGestureRecognizerDirectionLeft];
[self.tableView addGestureRecognizer:recognizer];
recognizer.delegate = self;
}
कॉल viewDidLoad
में इस विधि कड़ी चोट संभाल करने के लिए:
- (void)swipeLeft:(UISwipeGestureRecognizer *)gestureRecognizer {
CGPoint location = [gestureRecognizer locationInView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
... do something with cell now that i have the indexpath, maybe save the world? ...
}
ध्यान दें: अपने कुलपति इशारा पहचानकर्ता प्रतिनिधि को लागू करना चाहिए ।
- 1. UITableViewCell में हटाने के लिए स्वाइप करें सफेद पृष्ठभूमि है,
- 2. आईओएस: टैब के बीच बाएं/दाएं स्वाइप करें?
- 3. डिलीट बटन UItableviewcell छुपाया गया था या नहीं पता कैसे?
- 4. एंड्रॉइड - बाएं स्वाइप करें | दाएं। इशारा पता लगाने
- 5. बाएं-दाएं स्वाइप के साथ गतिविधि को कैसे बदलें
- 6. बटन के लिए बाएं/दाएं पैडिंग .setCompoundDrawablesWithIntrinsicBounds()?
- 7. एंड्रॉइड "हटाने के लिए बाएं से दाएं स्वाइप करें", सूची आइटम पर इशारा, आईसीएस स्टाइल
- 8. तालिका दृश्य में सेल को हटाने के लिए स्वाइप कैसे सक्षम करें?
- 9. दाएं से बाएं बटन को स्केल कैसे करें, एंड्रॉइड एनीमेशन
- 10. क्या मैं माउस के साथ क्रोम (पीसी) में एक स्वाइप (बाएं या दाएं) कर सकता हूं?
- 11. एक तत्व खींचते समय स्वाइप बाएं/दाएं तोड़ना
- 12. वेब पेज पर बाएं/दाएं स्वाइप करें, लेकिन डिफ़ॉल्ट स्वाइप अप/डाउन
- 13. हटाने के लिए स्वाइप tableview पंक्ति
- 14. UITableView हटाने के लिए स्वाइप करें: बटन और कार्रवाई को कस्टमाइज़ कैसे करें?
- 15. चार्ट कॉलम को संरेखित करें बाएं/दाएं
- 16. बाएं दाएं स्ट्रिंग को कैसे विस्फोट करें?
- 17. टैब सभी एपीआई स्तरों के लिए एंड्रॉइड में स्वाइप करें
- 18. कोई QGridLayout को ऊपर-बाएं से दाएं कैसे भरता है?
- 19. स्वाइप अप, स्वाइप नीचे, बाएं स्वाइप और दाईं ओर स्वाइप जेस्चर संभाल एक WinRT एप्लिकेशन
- 20. संपादन मोड पर काम नहीं कर रहे हटाने के लिए स्वाइप करें
- 21. डेटाबेस: रिकॉर्ड्स को हटाने या हटाने के लिए
- 22. स्ट्रिप बाएं/दाएं स्ट्रिंग (और चॉम्प)
- 23. बाएं, मध्य, दाएं
- 24. बॉक्सलेआउट को बाएं से दाएं
- 25. आईओएस सेगुए एनीमेशन बाएं से दाएं (क्षैतिज)
- 26. कार्ट में हटाए गए आइटमों के लिए पर्यवेक्षक
- 27. स्वाइप बनाम संपादित करें बटन iPhone
- 28. कस्टम UITableViewCell बटन कार्रवाई?
- 29. NSTableView टेक्स्ट संपादित करने के लिए सेल में कहीं भी क्लिक करने के लिए कैसे देखें?
- 30. एंड्रॉयड बाएं और दाएं मार्जिन
यदि आप कर सकते हैं, तो अपना कोड पोस्ट करें? –