如何以编程方式关闭展开的表格视图?

时间:2017-08-09 06:02:08

标签: ios objective-c iphone uitableview

我在视图控制器中有两个选项卡:在单击每个选项卡时,不同的数据显示在表格视图中,单元格在单击时可以展开和关闭。

问题在于当我在标签A中并在那里展开一个单元格时,然后单击标签B,加载新数据,该单元格仍然展开。如何以编程方式关闭它?

我正在使用- (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 { } 子类来执行扩展。

{{1}}

3 个答案:

答案 0 :(得分:0)

单击选项卡B时,请将表的keepOneSectionOpen属性设置为否。

Yourtable.keepOneSectionOpen = No;

答案 1 :(得分:0)

FZAccordionTableView GitHub repo我发现了这种方法:

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

这可能会做你想要的,但是不会在header file中声明,所以你不能直接调用它。

然而,你可以克隆repo,将行添加到头文件,添加+ commit + push到你的fork。然后在你的Podfile中使用that repo(或者你现在正在使用该库),这样你就可以使用你的框架,然后你可以调用该方法。

答案 2 :(得分:0)

点击每个标签,我就用了这个 [_tblProductServies closeAllSectionsExcept:-1]; 它的工作正常,谢谢大家。

相关问题