[英]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.