2011-03-19 10 views
11

मेरे पास एक तालिका दृश्य के साथ एक UIViewController क्लास है। viewDidLoad में:संपादन मोड में UITableView - 'संपादित करें' बटन स्थिति बदलता नहीं है

UIBarButtonItem *editIcon = [[[UIBarButtonItem alloc] 
initWithBarButtonSystemItem: UIBarButtonSystemItemEdit 
        target:self 
        action:@selector(toggleEditMode)] autorelease]; 

ते विधि 'toggleEditMode' में:

-(void)toggleEditMode{ 
if(self.theTable.editing) { 
    [theTable setEditing:NO animated:YES]; 
    [self.navigationItem.rightBarButtonItem setStyle:UIBarButtonItemStylePlain]; 
} 
else if ([callsArray count]!=0){ 
    [theTable setEditing:YES animated:YES]; 
    [self.navigationItem.rightBarButtonItem setStyle:UIBarButtonItemStyleDone]; 
} 

}

समस्या यह है कि संपादित करें बटन 'संपन्न' करना नहीं बदलता है। क्या कमी है? मैं सभी तरीकों घोषणा की है:

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath 
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath 
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 

धन्यवाद,

आर एल

उत्तर

22

क्यों सीधे UIViewController की -editButtonItem का उपयोग नहीं? और -setEditing:animated: विधि ओवरराइड करें।

// Assign the system's edit button, 
// it will change style when different edit status. 
self.navigationItem.rightBarButtonItem = self.editButtonItem; 

// The editButtonItem will invoke this method. 
- (void)setEditing:(BOOL)editing animated:(BOOL)animated { 
    [super setEditing:editing animated:animated]; 

    if (editing) { 
     // Execute tasks for editing status 
    } else { 
     // Execute tasks for non-editing status. 
    } 
} 
+0

बिल्कुल सही। अगर (संपादन) को (संपादन) करने के लिए बस बदल दिया गया है क्योंकि तालिका तालिका एक आईबीओलेट है। कक्षा UITableViewController से प्राप्त नहीं है। धन्यवाद, आरएल –

+0

आपका स्वागत है। :) – AechoLiu

+1

भले ही यह एक पुराना सवाल है, लेकिन मुझे यह समझने में मदद मिली कि मैं [सुपर सेट एडिटिंग: एनिमेटेड एनीमेशन: एनिमेटेड] भूल गया हूं; लाइन, यही कारण है कि मेरा काम नहीं कर रहा था। ;) इसे पोस्ट करने के लिए आपका धन्यवाद। – DataJock

0

तुम्हें यकीन callsArray खाली नहीं है?

toggleEditMode के अंदर ब्रेकपॉइंट रखें और देखें कि वहां क्या होता है।

संपादित

ठीक है, अपने प्रश्न को समझने के बाद, इस thread

+0

हाँ, मुझे यकीन है। तालिका संपादन मोड में प्रवेश करती है, और जब मैं पंक्ति को हटाता हूं तो यह काम करता है। यह समस्या नहीं है। समस्या यह है कि 'संपादन' बटन नहीं बदलता है, यह नाम बदलता है जब 'UONEableViewController क्लास' होता है। इसके बजाय, मेरी कक्षा एक UIViewController है जिसमें एक तालिका है। –

2

यह क्योंकि आप केवल बटन के शैली स्थापित कर रहे है पर एक नजर है (न कि उसके पाठ) जब आप मोड स्विच करते हैं। आप इस (या समतुल्य) क्या करने की जरूरत:

-(void)toggleEditMode{ 
    self.navigationItem.rightBarButtonItem.title = self.tableView.editing ? @"Done" : @"Edit"; 
+0

UITableViewController से कक्षा कब प्राप्त होती है जैसे काम क्यों नहीं करता है? क्या मैं तालिका में बटन असाइन नहीं कर सकता और ऐसा काम करता हूं? –

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