如何在ios objC中使用自定义视图扩展表格单元格?

时间:2016-03-17 12:45:11

标签: ios objective-c uitableview

首先,让我明白这个问题。

我可以展开并折叠UITableViewCell。我使用以下代码:

-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSIndexPath *indexPath1 = [NSIndexPath indexPathForRow:indexPath.row inSection:0];
    [self addOrRemoveSelectedIndexPath:indexPath1];
}

- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
    [self addOrRemoveSelectedIndexPath:indexPath];
}

- (void)addOrRemoveSelectedIndexPath:(NSIndexPath *)indexPath {
    BOOL containsIndexPath = [self.selectedIndexPaths containsObject:indexPath];
    if (containsIndexPath) {
        [self.selectedIndexPaths removeObject:indexPath];
    }else{
        self.selectedIndexPaths = [NSMutableArray new];
        [self.selectedIndexPaths addObject:indexPath];
    }
    [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}

我的问题是:当我展开单元格时,我想在单元格的底部显示自定义视图。我用XIB创建了自定义视图。但我不知道如何添加和删除它与然后轻拍单元格。

到目前为止,我只是尝试在didSelectRowAtIndexpath中添加单元格:

-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSIndexPath *indexPath1 = [NSIndexPath indexPathForRow:indexPath.row inSection:0];
    [self addOrRemoveSelectedIndexPath:indexPath1];

    LearnDetailCell *cell1 = (LearnDetailCell*)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:indexPath.row inSection:0]];
    ExpandView *expView = [[ExpandView alloc] init];
    [cell1 addSubview:expView];
}

但它不起作用。我的任务可能吗?

0 个答案:

没有答案