[英]How to close expanded table view cell programmatically?
我在视图控制器中有两个选项卡:单击每个选项卡时,表视图中会显示不同的数据,并带有单击时会展开和关闭的单元格。
问题是,当我进入选项卡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 = §ion;
NSDictionary *dict = listOfCategoryWhichHaveItems[section];
[self setDataAccordingToCategories:[dict valueForKey:kCategory]];
}
}
- (void)tableView:(FZAccordionTableView *)tableView didOpenSection:(NSInteger)section withHeader:(UITableViewHeaderFooterView *)header {
}
单击选项卡B时,请将表的keepOneSectionOpen属性设置为No。
Yourtable.keepOneSectionOpen = No;
在FZAccordionTableView
GitHub存储库中,我找到了此方法:
- (void)closeSection:(NSInteger)section withHeaderView:(nullable FZAccordionTableViewHeaderView *)sectionHeaderView
那可能会做您想做的事,但是它没有在头文件中声明,因此您不能直接调用它。
但是,您可以克隆存储库,将行添加到头文件中,添加+ commit + push到fork中。 然后使用该回购在Podfile(或无论你正在使用的库现在)让你在使用你的框架叉,那么你可以调用该方法。
单击每个选项卡时,我使用了此[_tblProductServies closeAllSectionsExcept:-1]; 现在一切正常,谢谢大家。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.