2015-10-20 5 views
8

मैं कुछ लेख खोजता हूं लेकिन मुझे वह नहीं मिला जो मैं ढूंढ रहा हूं। असल में, मैं प्रत्येक पंक्ति पर डिलीट बटन दिखाना चाहता हूं लेकिन मैं UITableView.editing प्रॉपर्टी का उपयोग नहीं करना चाहता हूं। क्योंकि ऐसा लगता है;UITableViewCell, स्वाइप के बिना स्वाइप-स्टाइल डिलीट बटन दिखाएं

enter image description here

"संपादन" बटन होगा। जब उपयोगकर्ता उस पर क्लिक करता है, तो हटाएं बटन स्वाइप-स्टाइल जैसा दिखता है।

क्या इस तरह के डिलीट बटन दिखाने का कोई मौका है;

enter image description here

हो सकता है कि वहाँ एक किसी तरह इससे निपटने के लिए है। अन्यथा, मैं इसके लिए कस्टम व्यू बनाने जा रहा हूं।

आपकी सलाह के लिए धन्यवाद। @property BOOL didPressEdit;

  • जोड़े UIButton जब संपादित दबाने UITableViewCell
  • को, didPressEditTRUE और UITableView पुनः लोड हो जाता है, जैसे कि cell.deleteButton.hidden = !didPressEdit; जो सभी उपलब्ध
  • बटन को हटाएँ बनाता है जब दबाने:

    - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { 
        // Return YES if you want the specified item to be editable. 
        return YES; 
    } 
    
    - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 
        if (editingStyle == UITableViewCellEditingStyleDelete) { 
    
         //Do something... 
        } 
    } 
    - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView 
          editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { 
    
        return UITableViewCellEditingStyleDelete; 
    
    } 
    
  • +0

    यू tableview में Image2 की तरह बटन को नष्ट करना चाहते हैं? –

    +0

    @bhavinramani हाँ मैं बटन हटाना चाहता हूं image2 की तरह दिखता है। वहां "संपादित करें" बटन होगा और जब आप उस पर क्लिक करेंगे तो सभी पंक्तियां छवि 2 की तरह दिखनी चाहिए। –

    +0

    कस्टम टेबलव्यू सेल आपके लिए जाने का एकमात्र तरीका है, क्योंकि सेल के अंत में डिलीट बटन एक बार में टेबलव्यू में सभी सेल के लिए दृश्यमान नहीं होगा (जैसा कि आपने अपने स्क्रीन शॉट में विस्तारित किया है) – viral

    उत्तर

    2
    • एक बूलियन संपत्ति जोड़ें हटाएं, डेटासोर्स सरणी से ऑब्जेक्ट को हटाएं, तालिका दृश्य पुनः लोड करें

    आशा है कि यह

    0

    मदद करता है आप उन कार्यों के लिए एक UITableView प्रतिनिधि विधि का उपयोग कर सकते हैं। इस प्रकार इस विधि को लागू करें:

    - (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath { 
        UITableViewRowAction *modifyAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Delete" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) { 
        // Respond to the action. 
        }]; 
        modifyAction.backgroundColor = [UIColor blueColor]; 
        return @[modifyAction]; 
    } 
    

    आप निश्चित रूप से अनेक कार्रवाइयों को लौट सकते हैं और पाठ और पृष्ठभूमि रंग अनुकूलित कर सकते हैं।

    इस पद्धति को लागू भी पंक्ति संपादन योग्य बनाने के लिए आवश्यक है:

    - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 
         if (editingStyle == UITableViewCellEditingStyleDelete) { 
          [self.objects removeObjectAtIndex:indexPath.row]; 
          [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; 
         } else if (editingStyle == UITableViewCellEditingStyleInsert) { 
          // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view. 
         } 
        } 
    

    आप अपने संपादित करें बटन पर क्लिक विधि editActionsForRowAtIndexPath कॉल करने के लिए की जरूरत है।

    -(void)buttonTouched:(id)sender{ 
    
         UIButton *btn = (UIButton *)sender; 
         NSIndexPath *indexPath = [NSIndexPath indexPathForRow:btn.tag inSection:0]; 
         [self tableView:self.tableView editActionsForRowAtIndexPath:indexPath]; 
        } 
    
        - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { 
         // Return NO if you do not want the specified item to be editable. 
         return YES; 
        } 
    
    +0

    मुझे यकीन नहीं है कि आप सवाल समझ गए। ओपी को स्वाइप किए बिना डिलीट बटन उपलब्ध कराने और संपादन बटन के टैप पर टेबलव्यू में सभी पंक्तियों के लिए विशिष्ट आवश्यकता है। मैं आपके द्वारा प्रदान किए गए उत्तर के साथ हासिल किए गए किसी भी को नहीं देख रहा हूं। – viral

    2
    -(NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath { 
        UITableViewRowAction *moreAction2 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"Edit" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){ 
         [self.heartCartTabel setEditing:NO]; 
         [self editButtonClicked:indexPath.row]; 
        }]; 
        moreAction2.backgroundColor = [UIColor blueColor]; 
    
        UITableViewRowAction *deleteAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Delete" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){ 
    
         [self tableView:self.heartCartTabel commitEditingStyle: UITableViewCellEditingStyleDelete forRowAtIndexPath:indexPath]; 
         //  [self.heartCartTabel deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic]; 
        }]; 
    
        return @[deleteAction, moreAction2]; 
    } 
    
    -(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{ 
        return YES; 
    } 
    
    - (IBAction)editButtonClicked:(int)indexNumber { 
    
    } 
    
    संबंधित मुद्दे