【问题标题】:How to close expanded table view cell programmatically?如何以编程方式关闭展开的表格视图单元格?
【发布时间】:2017-08-09 06:02:08
【问题描述】:

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

问题是,当我在选项卡 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 {
}

【问题讨论】:

    标签: ios objective-c iphone uitableview


    【解决方案1】:

    请在单击选项卡 B 时将表格的 keepOneSectionOpen 属性设置为“否”。

    Yourtable.keepOneSectionOpen = No;
    

    【讨论】:

      【解决方案2】:

      FZAccordionTableViewGitHub repo我找到了这个方法:

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

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

      但是,您可以克隆 repo,将行添加到头文件,添加 + 提交 + 推送到您的 fork。然后在你的 Podfile 中使用that repo(或者你现在正在使用这个库),这样你就可以使用你的框架分支,然后你就可以调用该方法了。

      【讨论】:

        【解决方案3】:

        点击每个标签时,我使用了这个 [_tblProductServies closeAllSectionsExcept:-1]; 现在工作正常,谢谢大家。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2019-06-24
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多