2013-02-27 19 views
11

में UITableView सेल मैं इसे की क्लिक पर tableview सेल का विस्तार करना चाहते हैं। एक टेबलव्यू है जिसमें दो कोशिकाएं विस्तार योग्य हैं और अन्य नहीं हैं। जब मैं विस्तारणीय सेल पर क्लिक करता हूं तो मुझे इसकी आवश्यकता होती है, इसे इसके नीचे सेल्स दिखाना चाहिए और फिर से क्लिक करना इसे छिपाना चाहिए। इसे परिभाषित करने के नीचे एक छवि है।विस्तृत UITableViewstylePlain

enter image description here

मैं कैसे इस कार्यक्षमता प्राप्त कर सकते हैं, इसके बाद के संस्करण के लिए मार्गदर्शन करें। अग्रिम धन्यवाद।

+0

क्या आपकी समस्या हल हो गई है? – Bhavin

+0

नहीं, अभी तक नहीं .... –

+0

क्या आपने मेरा उत्तर चेक किया है? – Bhavin

उत्तर

12

Here विस्तार UITableView

के साथ पूरा ट्यूटोरियल यहाँ उस के लिए कोड स्निप है।

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if ([self tableView:tableView canCollapseSection:indexPath.section]) 
    { 
     if (!indexPath.row) 
     { 
      // only first row toggles exapand/collapse 
      [tableView deselectRowAtIndexPath:indexPath animated:YES]; 

      NSInteger section = indexPath.section; 
      BOOL currentlyExpanded = [expandedSections containsIndex:section]; 
      NSInteger rows; 

      NSMutableArray *tmpArray = [NSMutableArray array]; 

      if (currentlyExpanded) 
      { 
       rows = [self tableView:tableView numberOfRowsInSection:section]; 
       [expandedSections removeIndex:section]; 

      } 
      else 
      { 
       [expandedSections addIndex:section]; 
       rows = [self tableView:tableView numberOfRowsInSection:section]; 
      } 

      for (int i=1; i<rows; i++) 
      { 
       NSIndexPath *tmpIndexPath = [NSIndexPath indexPathForRow:i 
                   inSection:section]; 
       [tmpArray addObject:tmpIndexPath]; 
      } 

      UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 

      if (currentlyExpanded) 
      { 
       [tableView deleteRowsAtIndexPaths:tmpArray 
           withRowAnimation:UITableViewRowAnimationTop]; 

       cell.accessoryView = [DTCustomColoredAccessory accessoryWithColor:[UIColor grayColor] type:DTCustomColoredAccessoryTypeDown]; 

      } 
      else 
      { 
       [tableView insertRowsAtIndexPaths:tmpArray 
           withRowAnimation:UITableViewRowAnimationTop]; 
       cell.accessoryView = [DTCustomColoredAccessory accessoryWithColor:[UIColor grayColor] type:DTCustomColoredAccessoryTypeUp]; 

      } 
     } 
    } 
} 

के रूप में चित्र में नीचे दिखाया गया

enter image description here

This और this एक समाधान में भी मदद आप कैसे विस्तार tableview

+0

यह समूह तालिका है, मैं केवल सादे तालिका के लिए पूछ रहा हूं। –

+0

@iPhone आपने [यह] जांच लिया [http://www.roostersoftstudios.com/2011/04/14/iphone-uitableview-with-animated-expanding-cells/) सादा तालिका – swiftBoy

+0

के लिए मैंने पहले ऐसा नमूना देखा है प्रश्न पोस्ट करना, यह खंड का विस्तार करता है, सादे में हम केवल एक ही खंड को केवल सेल को विस्तारित करने की आवश्यकता है। –

3

मुझे लगता है कि तुम क्या चाहते पहले से ही एप्पल द्वारा दिया जाता है। आप तालिका देखें एनिमेशन और जेस्चर के शीर्षक के अंतर्गत एप्पल द्वारा प्रदान की Sample Code पर एक नज़र ले जा सकते हैं।

0

इस प्रतिनिधि द्वारा संभव है प्रबंधित करने के लिए समझने के लिए

- (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath { 
     //write code here 
    } 
+0

क्या आपने कभी इस उद्देश्य के लिए इस विधि का उपयोग किया है और क्या आप इस –

4

ठीक है, मैं क्या सोच रहा हूँ है, शीर्षक, घटनाक्रम, ओवरहेड और दोस्त पृष्ठभूमि के लिए UIImageView, UILabel खिताब के लिए, और UIButton के लिए विस्तार के साथ कस्टम UIView होगा। तो मूल रूप से

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 

खिताब आपने की वापसी गिनती हो रही है।

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 

प्रत्येक शीर्षक के लिए UIView वापस लौटा रहा है।

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 

कि शीर्षक के भीतर पंक्तियों की गिनती हो रही है। आपको इसके लिए एक सरणी बनाए रखने की आवश्यकता हो सकती है।

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath; 

सेल आइटम

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section 

शुरू में की ऊंचाई होने यह सभी वर्गों के लिए 0 (शून्य), जब पर उपयोगकर्ता नल का विस्तार होना चाहिए, यह पंक्तियों की संख्या के संबंध में वृद्धि की जानी चाहिए * उस खंड के भीतर सेल ऊंचाई

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 

आप विस्तार के लिए सभी पंक्तियों की स्थापना के लिए कुछ अच्छे तर्क की आवश्यकता हो सकती

आपका विस्तार बटन कार्यों कुछ की तरह,

- (void) expandSection:(UIButton *)sender; 

है कि आप पहचान सकते हैं जो अनुभाग sender.tag का उपयोग कर विस्तार किया जाना है , तो टैग को ठीक से जोड़ना न भूलें। वर्तमान अनुभाग को स्टोर करने के लिए आपको .h फ़ाइल में int की आवश्यकता हो सकती है, और - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section डेटासोर्स विधि में उपयोग किया जा सकता है।

2

मैंने नीचे उदाहरण स्रोत कोड दिया है। आप अपनी आवश्यकता के आधार पर इस उदाहरण को अनुकूलित कर सकते हैं।

स्रोत कोड लिंक: Click here

आउटपुट स्क्रीन:

enter image description here

2

JKExpandTableView एमआईटी लाइसेंस प्राप्त आईओएस पुस्तकालय कि expandable table view लागू करता है। शामिल नमूना परियोजना को भी जांचना सुनिश्चित करें।

screenshot

0

स्वीकार किए जाते हैं जवाब सच है लेकिन लिंक पुरानी हो चुकी है। यहाँ से
https://github.com/cocoanetics/Examples

डाउनलोड DTCustomColoredAccessory.h और .m फ़ाइलें: यहां से

डाउनलोड ExpandableTableCells परियोजना: https://github.com/Cocoanetics/DTFoundation/tree/develop/Core/Source/iOS

DTCustomColoredAccessory रखो कि उदाहरण के लिए आप अतिरिक्त काम करने के लिए काम करने के लिए है ExpandableTableCells परियोजना में फ़ाइलें।

वहां आपके पास यह एक कामकाजी उदाहरण है, इसे संपादित करना और शून्य से लिखने की बजाय वहां से स्थानांतरित करना आसान है।

+0

के लिए नमूना कोड पोस्ट कर सकते हैं मैंने 'ExpandableTableCells प्रोजेक्ट डाउनलोड करें' डाउनलोड किया है और डाउनलोड DTCustomColoredAccessory.h और .m फ़ाइलों को जोड़ा है। लेकिन मुझे एक त्रुटि मिल रही है "त्रुटि: लिंकर कमांड निकास कोड 1 के साथ विफल रहा (उपयोग -v आमंत्रण देखने के लिए)" क्या आप इसके साथ मदद कर सकते हैं? –

+0

क्या आप त्रुटि में अधिक जानकारी पोस्ट कर सकते हैं? – Esqarrouth

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