2017-08-09 61 views
0

我在視圖控制器中有兩個選項卡:單擊每個選項卡時,不同的數據顯示在表格視圖中,單擊時展開和關閉的單元格。如何以編程方式關閉展開的表格視圖單元格?

問題是,當我在標籤A中,並在那裏展開一個單元格,然後點擊標籤B,加載新數據,那個單元格仍然展開。如何以編程方式關閉它?我使用FZAccordionTableView子類來執行擴展。

- (UIView *)tableView:(FZAccordionTableView *)tableView viewForHeaderInSection:(NSInteger)section { 
    HeaderView *view = [tableView dequeueReusableHeaderFooterViewWithIdentifier:kAccordionHeaderViewReuseIdentifier]; 
    if (listOfCategoryWhichHaveItems.count > 0) { 
     if (arrCategory.count > 0) { 
      arrCategory1 = _btnProduct.selected == YES ? [arrCategory objectAtIndex:0] : [arrCategory objectAtIndex:1]; 
      NSDictionary *dict = arrCategory1[section]; 
      view.lblHeaderTitel.text = [dict valueForKey:kCategory]; 
      bool isSelected = [tableView isSectionOpen:section]; 
     } 
    } 
    return view; 
} 

#pragma mark - <FZAccordionTableViewDelegate> - 

- (void)tableView:(FZAccordionTableView *)tableView willOpenSection:(NSInteger)section withHeader:(UITableViewHeaderFooterView *)header { 
    loadFirstTime = false; 
    [tableView reloadSections:[NSIndexSet indexSetWithIndex:section] withRowAnimation: UITableViewRowAnimationAutomatic]; 
    if (listOfCategoryWhichHaveItems.count > 0) { 
     _sectionNumber = &section; 
     NSDictionary *dict = listOfCategoryWhichHaveItems[section]; 
     [self setDataAccordingToCategories:[dict valueForKey:kCategory]]; 
    } 
} 

- (void)tableView:(FZAccordionTableView *)tableView didOpenSection:(NSInteger)section withHeader:(UITableViewHeaderFooterView *)header { 
} 

回答

0

請您表的keepOneSectionOpen屬性設置爲不上點擊選項卡B.

Yourtable.keepOneSectionOpen = No; 
0

FZAccordionTableViewGitHub repo,我發現這個方法:

- (void)closeSection:(NSInteger)section withHeaderView:(nullable FZAccordionTableViewHeaderView *)sectionHeaderView 

這可能會做什麼你想,但是它並沒有在header file中聲明,所以你不能直接調用它。

但是,您可以克隆回購,將該行添加到頭文件,將+ commit + push添加到您的分支。然後在你的Podfile中使用that repo(或者你現在正在使用這個庫),所以你使用了框架的fork,然後你可以調用這個方法。

0

點擊每個標籤,我用這個 [_tblProductServies closeAllSectionsExcept:-1]; 現在工作正常,謝謝大家。

相關問題