2012-08-29 15 views
6

मैं एक ऐसा एप्लीकेशन कर रहा हूं जिसके लिए अधिक जानकारी दिखाने के लिए कोशिकाओं के विस्तार की आवश्यकता है। मैंने एक कस्टम सेल का उपयोग किया है और उन्हें UItableview में जोड़ा है। जब मैं सेल पर क्लिक करता हूं तो यह ठीक से एनिमेट करता है और नीचे जाता है और जब मैं फिर से क्लिक करता हूं तो यह ऊपर जाता है, यह सेल की ऊंचाई को बदलकर किया जाता है। वास्तविक कस्टम सेल आकार सामान्य रूप से दिखाए जाने वाले सेल से बड़ा होता है। जब मैं सेल पर क्लिक करता हूं तो पूरे सेल को दिखाया जाता है। केवल मेरे पास समस्या है जो डेटा का अतिप्रवाह है। सेल का चयन नहीं होने पर इन आंकड़ों को छुपाया जाना चाहिए। केवल तभी जब यह चुना जाता है तो डेटा दिखाया जाना चाहिए।यूआईटेबल सेल ओवरफ्लो आईओएस

मैंने विभिन्न कलाकृतियों को संदर्भित किया, रंग सेटिंग को बदलने की कोशिश की, मेरे लिए काम नहीं किया। मुझे इस प्रश्न में iphone uitablecellview overflow में एक ही तरह की समस्या है, जवाब की कोशिश की लेकिन यह काम नहीं किया।

मुझे केवल कस्टम सेल के निचले भाग को छिपाने के तरीके की आवश्यकता है, जब इसे विस्तारित नहीं किया जाता है, और इसे विस्तारित होने पर दिखाएं ...!

ये मेरी स्क्रीन शॉट्स हैं

When it is loaded जब यह भरी हुई है When I click on a cell जब मैं एक सेल पर क्लिक करें] When I click on the 2nd cell जब मैं 2 सेल पर क्लिक करें When I click on the cell which is expanded
जब मैं सेल पर क्लिक करें जो पहले ही विस्तारित है ये कोड स्निप हैं जिनका मैंने उपयोग किया है ....

// Declaring the SearchResultTable. 
    CGRect filterFrame = CGRectMake(0,31, 320, 400); 
    self.searchResultTable = [[UITableView alloc] initWithFrame:filterFrame]; 
    self.searchResultTable.dataSource = self; 
    self.searchResultTable.delegate = self; 
    self.searchResultTable.backgroundColor = [UIColor whiteColor]; 
    self.searchResultTable.separatorStyle = UITableViewCellSeparatorStyleSingleLine; 
    self.searchResultTable.separatorColor = [UIColor lightGrayColor]; 
    [self.view addSubview:self.searchResultTable]; 

//Adding cells 
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath(NSIndexPath *)indexPath { 
    static NSString *CellIdentifier = @"ExpandedSearchResultTableCell"; 


    ExpandedSearchResultTableCell *cell = (ExpandedSearchResultTableCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 


    if (cell == nil) 
    { 
     cell.contentView.clipsToBounds = YES; 
     NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ExpandedSearchResultTableCell" owner:self options:nil]; 
     cell = [nib objectAtIndex:0]; 


    } 

    cell.productNameLable.text = @"Only this should be shown"; 
    cell.productListLabel.text = @"This Should be hidden.. Only shown when expanded"; 
    [email protected]"This Should be hidden.. Only shown when expanded"; 
    cell.productTargetLable.text= @"This Should be hidden.. Only shown when expanded"; 
    [email protected]"This Should be hidden.. Only shown when expanded"; 
    [email protected]"This Should be hidden.. Only shown when expanded";; 


    return cell; 
} 


//on click event 
(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 




    // Deselect cell 
    [tableView deselectRowAtIndexPath:indexPath animated:TRUE]; 

    // Toggle 'selected' state 
    BOOL isSelected = ![self cellIsSelected:indexPath]; 

    // Store cell 'selected' state keyed on indexPath 
    NSNumber *selectedIndex = [NSNumber numberWithBool:isSelected]; 
    [selectedIndexes setObject:selectedIndex forKey:indexPath]; 

    // This is where magic happens... 
    [searchResultTable beginUpdates]; 
    [searchResultTable endUpdates]; 
} 

//Getting the height depending on expanded or not 
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 
    // If our cell is selected, return double height 
    if([self cellIsSelected:indexPath]) { 
     return kCellHeight * 3.0; 
    } 

    // Cell isn't selected so return single height 
    return kCellHeight; 
} 

उत्तर

1

ठीक है, मैं यह एक एकल झंडा और didSelectRowAtIndexPath में cellForRowAtIndexPath सेल के लिए एक संदर्भ का उपयोग करके किया गया। और पतन और खिंचाव के अनुसार मेरे लेबल दिखने और छुपा सेट। ध्वज तदनुसार अद्यतन किया जाता है कि सेल का चयन किया गया है या नहीं ... !!

आपके लिए धन्यवाद सभी के लिए धन्यवाद ..!

1

आप देख रहे हैं सादे tableview प्रकार के साथ सेल के विस्तार के लिए,

iPhone UITableView with animated expanding cells

और अगर मामले में आप समूहीकृत tableview उपयोग कर रहे हैं और अनुभाग शीर्ष लेख के चयन पर विस्तार करना चाहते,

Table View Animations and Gestures

+0

मैंने पहले ही एनीमेशन भाग पूरा कर लिया है .. मुझे केवल सेल के कुछ हिस्सों को छिपाने के बारे में जानने की जरूरत है ... वैसे भी मैं आपको लिंक का संदर्भ दूंगा ... मैंने पहले ही – Gihan

0

ओउप्स, कोड के लोड ने आपकी पोस्ट को गंदे बना दिया।

मैं आपके कोड से नहीं जा रहा हूं।

मैं आपको तर्क समझाऊंगा।

  1. केवल यह प्रदर्शित होना चाहिए आपके indexpath.row = 0;
  2. खंड में पंक्तियों की संख्या यदि चयनित है, तो पता चला + बाकी 1.
cell.productNameLable.text = @"Only this should be shown"; 
cell.productListLabel.text = @"This Should be hidden.. Only shown when expanded"; 
[email protected]"This Should be hidden.. Only shown when expanded"; 
cell.productTargetLable.text= @"This Should be hidden.. Only shown when expanded"; 
[email protected]"This Should be hidden.. Only shown when expanded"; 
[email protected]"This Should be hidden.. Only shown when expanded";; 

यह आपके कोड गंदा बनाता है 1 कोशिकाओं की गिनती होगी। यदि आप एक सेल में सभी डेटा दिखाना चाहते हैं, और जब आप एक सेक्शन चुनते हैं तो केवल एक सेल जोड़ा जाता है, मैं इन सभी को विभिन्न कोशिकाओं में जोड़ने का सुझाव दूंगा।

मैं अभी भी उलझन में हूँ तुम क्यों इन लंबे कोडिंग कर रहे हैं, Please refer this answer for better explanation

+0

की जांच की है सवाल गलत है ... मुझे इसे कच्चे 0 में जोड़ने की ज़रूरत नहीं है ... ये विवरण मेरी मेज के हर सेल में हैं .. मुझे इन विवरणों को कस्टम सेल बोटम भाग में दिखाने की ज़रूरत है ... लेकिन यह हिस्सा होना चाहिए दिखाया गया है कि जब मैं वास्तव में सेल पर क्लिक करता हूं .. परीक्षण उद्देश्यों के लिए केवल मैं इन तारों को जोड़ रहा हूं ... – Gihan

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