2010-09-10 17 views
14

के लिए हटाने के लिए स्लाइड को अक्षम करने के लिए कैसे करें क्या कोई जानता है कि uitableview में 'स्लाइड-टू-डिलीट' को अक्षम कैसे करें?UITableView

मैं अभी भी पंक्तियों को हटाने में सक्षम होना चाहता हूं जबकि तालिका संपादन मोड में है।

+1

आप कभी भी अपने अन्य सवालों के जवाब को छोड़कर पर विचार किया? – Eiko

उत्तर

30

मेरा है:

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    return self.editing ; 
} 
13

सबसे पहले, यह पुष्टि करने के लिए कि कोई तालिका सेल हटाया जा सकता है, बस canEditRowAtIndexPath को उत्तर दें।

-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { 
    // Return YES or NO 
    return(YES); 
    } 
}

फिर, वास्तव में प्रतिबद्ध करने के लिए टेबल सेल जवाब को हटाने के लिए।

-(void)tableView:(UITableView *)tv commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 
    if (editingStyle == UITableViewCellEditingStyleDelete) { 
    // Delete your data 

    // Delete the table cell 
    [self.tableView deleteRowAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; 
    } 
}

शुभकामनाएँ मैट Stijlaart!

+2

यह सवाल का उत्तर कैसे देता है? – BoltClock

+0

पहला कोड नमूना आपको स्वाइप-टू-डिलीट अक्षम करने देता है। संपादन कोड सक्रिय होने पर दूसरा कोड नमूना आपको पंक्ति को हटाने देता है। मुझे यकीन था कि यह आपकी मदद कर सकता है ... सम्मान – rjobidon

+1

कोड के पहले ब्लॉक में, यह "शून्य" –