ExpandableTableView:任何时候都只能扩展1行

时间:2014-05-14 08:49:36

标签: ios objective-c

我正在使用ExpandableTableView。 在这里a link

  1. 任何时候只能展开1行,而其他行则会崩溃。
  2. 展开行时,屏幕上的任何点按都会折叠展开的行。
  3. 我怎么能得到它?

1 个答案:

答案 0 :(得分:0)

ExpandableTableView.h

采用上一节变量

NSInteger presection;

在ExpandableTableView.m

- (id)initWithCoder:(NSCoder *)aDecoder方法设置presection intial Value

presection=-1;

替换didSelectRowAtIndexPath

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    // either expand the section or call the  delegates method if already expanded


    if ([_expandedSectionIndexes containsIndex:indexPath.section]) {
        // we're already expanded
        [self contractSection:presection]; // Contrace Previos Section

        if (indexPath.row == 0) {
            // close the section
            [self contractSection:indexPath.section];
            [super deselectRowAtIndexPath:indexPath animated:YES];
        } else {
            if ([_expandableDelegate respondsToSelector:@selector(tableView:didSelectRowAtIndexPath:)]) {
                [_expandableDelegate tableView:self didSelectRowAtIndexPath:[NSIndexPath indexPathForRow:indexPath.row - 1 inSection:indexPath.section]];
            }
        }
    } else if (indexPath.row == 0 && _ungroupSingleElement && [_expandableDataSource tableView:self numberOfRowsInSection:indexPath.section] == 1) {
        if ([_expandableDelegate respondsToSelector:@selector(tableView:didSelectRowAtIndexPath:)]) {
            [_expandableDelegate tableView:self didSelectRowAtIndexPath:indexPath];
        }
    } else {
        if (presection!=-1) {
            [self contractSection:presection];
        }
        presection=indexPath.section;
        [self expandSection:indexPath.section];
        [super deselectRowAtIndexPath:indexPath animated:YES];
    }
}