2011-12-15 8 views
5

मैं उस पर स्थैतिक कोशिकाओं के साथ तालिकादृश्य के अंदर एक अनुभाग को हटाने या छिपाने की कोशिश कर रहा हूं। मैं इसे viewDidLoad फ़ंक्शन में छिपाने की कोशिश कर रहा हूं। यहां कोड है:स्थिर सेल तालिकादृश्य से अनुभागों को कैसे हटाएं

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    [self.tableView beginUpdates]; 
    [self.tableView deleteSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:YES]; 
    [self.tableView endUpdates]; 

    [self.tableView reloadData]; 
} 

अभी भी अनुभाग दिखाई देते हैं। मैं इसमें स्टोरीबोर्ड का उपयोग कर रहा हूं। क्या आप कृपया मेरी मदद कर सकते हैं? धन्यवाद!

उत्तर

-2

ऐसा लगता है कि reloadData तालिका दृश्य बनाता है फिर से पढ़ने के लिए डेटा स्रोत। reloadData पर कॉल करने से पहले आपको डेटा स्रोत से डेटा भी हटा देना चाहिए। यदि आप सरणी का उपयोग कर रहे हैं, तो reloadData पर कॉल करने से पहले removeObject: के साथ इच्छित ऑब्जेक्ट को हटा दें।

5

यहां मिले उत्तर की जांच करें। How to remove a static cell from UITableView using Storyboards स्थिर कोशिकाओं का उपयोग करते समय किसी समस्या का एक बग होने लगता है। उम्मीद है की यह मदद करेगा।

6

मैंने पाया यह सबसे सुविधाजनक numberOfRowsInSection अधिभावी द्वारा वर्गों को छिपाने के लिए।

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    if (section == 1) 
     // Hide this section 
     return 0; 
    else 
     return [super tableView:self.tableView numberOfRowsInSection:section]; 
} 
+0

यह मेरे उद्देश्य के अनुकूल है, लेकिन ऐसा करने के बाद वहां कुछ लंबवत स्थान बना हुआ है। – guptron

+0

क्या ओपी चाहता था, महान आत्मा! – Tumtum

0

यहां आप जाते हैं। यह भी लंबवत अंतरिक्ष को हटा देता है।

NSInteger sectionToRemove = 1; 
CGFloat distance = 10.0f; // minimum is 2 since 1 is minimum for header/footer 
BOOL removeCondition; // set in viewDidLoad 

/** 
* You cannot remove sections. 
* However, you can set the number of rows in a section to 0, 
* this is the closest you can get. 
*/ 

- (NSInteger)tableView:(UITableView *)tableView 
numberOfRowsInSection:(NSInteger)section { 
    if (removeCondition && section == sectionToRemove) 
    return 0; 
    else 
    return [super tableView:self.tableView numberOfRowsInSection:section]; 
} 

/** 
* In this case the headers and footers sum up to a longer 
* vertical distance. We do not want that. 
* Use this workaround to prevent this: 
*/ 
- (CGFloat)tableView:(UITableView *)tableView 
    heightForFooterInSection:(NSInteger)section { 

    return removeCondition && 
       (section == sectionToRemove - 1 || section == sectionToRemove) 
      ? distance/2 
      : distance; 
} 

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

    return removeCondition && 
       (section == sectionToRemove || section == sectionToRemove + 1) 
      ? distance/2 
      : distance; 
} 
संबंधित मुद्दे