2012-09-07 7 views
12

मैं जानना चाहता हूं कि मैं क्या खो रहा हूं क्योंकि डिलीट बटन छुपाते समय मेरा सेल एनिमेट नहीं होता है। डिलीट बटन खत्म करने से पहले लेबल मूल स्थिति पर वापस कूदता है।कस्टम यूटेबलव्यूसेल सामग्री डिलीट बटन छुपाते समय एनिमेटेड नहीं है

जब मैं हटाएँ बटन दिखाने के लिए दौर संपादन दृश्य टैप करते हैं, लेबल एनीमेशन काम करता है:

Screenshot of cells where the delete button appears

लेकिन जब मैं इसे फिर से हटाएँ बटन को छिपाने के लिए नल, लेबल के आंदोलन नहीं है एनिमेटेड:

Screenshot of cells where the delete button disappears

नोट: ये स्क्रीनशॉट निम्न कोड से नहीं बनाई गई हैं। लेकिन वे समस्या दिखाते हैं।

// Customize the appearance of table view cells. 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"Cell"; 

    homeCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[homeCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; 
    } 

    // Set up the cell 
    Consumed *drinkObj = [self.appDelegate.consumedDrinksArray objectAtIndex:indexPath.row];   
    cell.titleLabel.text = drinkObj.drinkName; 
    NSString *detailTextTime = [NSDate stringFromDate:drinkObj.dateConsumed withFormat:@"h:mma"]; 

    NSString *detailTextrelative = [relativeDateTransformer transformedValue:drinkObj.dateConsumed]; 

    NSString *detailText = [NSString stringWithFormat:@"%@ %@ ", detailTextTime,detailTextrelative]; 
    cell.timeLabel.text = detailText; 

    cell.stdDLabel.text = @"999.0"; //[NSString stringWithFormat:@"%@", drinkObj.standardDrinks]; 
    cell.stdDLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin; 
    cell.titleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin; 
    cell.timeLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin; 
    cell.selectionStyle = UITableViewCellSelectionStyleNone; 
    return cell; 
} 
+1

मैं एक ही समस्या है , आपका वीडियो 404 है और वहां पर्याप्त कोड था। मुझे लगता है कि मैंने आपके प्रश्न में सुधार किया है। यदि आप इसे वापस रोल करने के लिए स्वतंत्र महसूस करते हैं। –

+1

आपकी 'होमसेल' कक्षा कैसी दिखती है? आप किस तरीके से ओवरराइड कर रहे हैं? – Sulthan

+1

विशेष रूप से, 'layoutSubviews' overriden है? – Sulthan

उत्तर

6

संपादित करें: मुझे लगता है कि बग पहले उदाहरण में जो कुछ मैंने समझा था उससे अलग है। चलो मेरा जवाब सही करें। यदि मैं सही हूं, तो आपका डिलीट बटन एनीमेशन के साथ सही ढंग से गायब हो जाता है, लेकिन सामग्री दृश्य एनिमेटिंग के बिना स्वयं का आकार बदलता है (बटन एनिमेटिंग के पीछे जा रहा है)।

यह मामला आपको स्वयं एनीमेशन का प्रबंधन करना है। मैं आपको यह मानता हूं कि आप रोटेशन का समर्थन नहीं कर रहे हैं। यदि आप रोटेशन का समर्थन करना चाहते हैं, तो आपको अधिक कोड की आवश्यकता होगी :-)

यहां एक नमूना प्रोजेक्ट है (वहां बहुत सारे कोड हैं क्योंकि मैंने मानक मास्टर-विवरण xcode टेम्पलेट का उपयोग किया है, केवल कस्टम सेल पर ही देखें) : Sample Project

यह आपके कोड पर लागू करने के लिए:

पहली बात, सेल के दाईं ओर लेबल की autoresizing मुखौटा बदल बाईं ओर लंगर डालना।

मुझे यकीन है कि अगर सही लेबल stdDLabel है नहीं कर रहा हूँ, मैं इसे

// if the right margin is flexible, the left-top-bottom are fixed 
cell.stdDLabel.autoresizingMask = UIViewAutoresizingFlexibleRightMargin; 

मान लेंगे अपने सेल उपवर्ग में setEditing:animated: विधि इस तरह ओवरराइड:

-(void)setEditing:(BOOL)editing animated:(BOOL)animated 
{ 
    // this is an array of the labels/view that you want to animate 
    NSArray *objectsToMove = @[self.stdDLabel]; 
    // this is the amount of pixel to move - the width of the delete button 
    float pixelToMove = 70.0f; 

    float animationDuration = 0.3f; 

    // calculating the delta. If set editing, move from right to left. otherwise, from left to right 
    float delta = (editing) ? -pixelToMove : pixelToMove; 

    // put the move code in a block for avoid repeating code in the if 
    void (^moveBlock)() = ^{ 
     for (UIView *view in objectsToMove) { 
      view.center = CGPointMake(view.center.x + delta, view.center.y); 
     } 
    }; 

    // we want to move the labels only if editing is different from the current isEditing state 
    if (editing != self.isEditing) 
    { 
     // execute the move block, animated or not 
     if (animated) 
      [UIView animateWithDuration:animationDuration animations:moveBlock]; 
     else 
      moveBlock(); 
    } 

    // call the super implementation 
    [super setEditing:editing animated:animated]; 
} 
+1

देखें क्योंकि मैं हमेशा संपादन मोड में हूं 'सेट संपादन: एनिमेटेड:' मुझे बहुत मदद नहीं करेगा, लेकिन यह वैसे भी एक अच्छा जवाब है। मुझे लगता है कि मैं सिर्फ इस व्यवहार को सेब फ्रेमवर्क में एक बग के रूप में मानूंगा। थोड़ा लाभ के लिए ज्यादा काम करने के लिए ठीक नहीं होगा। धन्यवाद। –

+1

आप सही हैं, मैंने नहीं सोचा कि आप हमेशा संपादन मोड में हैं। मुझे लगता है (बाद में कोशिश करेगा) कि आप ओवरराइडिंग 'WillTransitionToState:' विधि को हल कर सकते हैं, जिसे हर बार सेल स्टेटस प्रकार के पैरामीटर के साथ बदल दिया जाता है UITableViewCellStateMask – LombaX

3

मैं अपने कोड के सभी की जाँच नहीं था, लेकिन यकीन है कि के लिए आप हटाना के प्रत्येक पक्ष पर शुरू/अंत अद्यतन जोड़ने की आवश्यकता होगी ...

[self.drinksTableView beginUpdates]; 
[self.drinksTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; 
[self.drinksTableView endUpdates]; 

... करने के लिए एनीमेशन प्राप्त करें।

+1

हाय दान किया है, उत्तर के लिए धन्यवाद। वह पंक्ति एनीमेशन कार्यों को हटा देता है। मेरा मतलब है कि पहली बार "-" से "|" चुनने पर, एनीमेशन काम करता है। हालांकि "|" से बदलते समय "-", कोई एनीमेशन नहीं है। – Desmond

3

आप इस कार्य को gesturerecognizer का उपयोग करके कर सकते हैं। यह आपको अपने सेल को प्रबंधित करने में मदद कर सकता है। और डिफॉल्ट डिलीट बटन के बजाय सेल पर एक कस्टमम डिलीट बटन भी जोड़ सकता है।

2
tableView:didEndEditingRowAtIndexPath: में

इसलिए उनके फ्रेम

- (void)tableView:(UITableView*)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    homeCell *cell = (homeCell *)[tableView cellForRowAtIndexpath:indexPath]; 

    UILabel *labelToBeRelocated = (UILabel *)[cell viewWithTag:YOUR_LABEL_TAG]; 

    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.25f]; 

    [labelToBeRelocated setFrame:CGRectMake(New_PosX , New_PosY , width , height)]; 

    [UIView commitAnimations]; 
} 

के बाद से ऊपर प्रतिनिधि विधि के बाद EditingButton (बटन को हटाएँ) UITableViewCell में छिपा हुआ है कहा जाता है, settign द्वारा UILabels मैन्युअल रूप से पुनः लगाने का कार्य peform हटाने के बटन को छिपाने के बाद ही यूलाबेल अपनी स्थिति फिर से खोजेगा। आशा है कि यह आपकी मदद करेगा।

+1

यह काम नहीं करेगा। यदि लेबल सही-एंकर किया गया है, तो यह तुरंत कूद जाएगा क्योंकि सामग्री दृश्य एनीमेशन (बग?) के बिना अपने फ्रेम को बदलता है। यदि आपने लेबल को एंकर किया है, तो बटन दिखाई देने पर आपको दाएं से बाएं स्थानांतरित करना होगा, और गायब होने पर बाएं से दाएं (दूसरी विधि में)। मेरा समाधान – LombaX

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