2014-10-02 58 views
0

当您单击TableView内的单元格时,它将展开。 如何实现,这是下面的方法:如何“缩小”TableView中的所有单元格并展开单击的单元格

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

if ([self.topicsArray containsObject:indexPath]) 
{ 
    [self.topicsArray removeObject:indexPath]; 
} 
else 
{ 
    [_topicsArray addObject:indexPath]; 

} 

[_tableView beginUpdates]; 
[_tableView endUpdates]; 

} 

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

CGFloat kExpandedCellHeight = 240; 
CGFloat kNormalCellHeigh = 115; 


    if ([_topicsArray containsObject:indexPath]) 
    { 

     return kExpandedCellHeight; 
    } 
    else 
    { 
     return kNormalCellHeigh; 
    } 


} 

我想不出什么如何做的是 - 如何“缩水”的TableView中的所有单元格之前,我展开一个点击?

+0

尝试'[_tableView beginUpdates]之间'[_tableView reloadData]'; [_tableView endUpdates];' – Elgert 2014-10-02 12:42:26

+0

那什么也没做:( – SteBra 2014-10-02 12:44:01

+0

'endUpdates'之后试试它应该可以工作,这再次调用高度的重新计算 – Elgert 2014-10-02 12:47:19

回答

0

aha我知道了你不要从数组中删除索引。尝试[topicsArray removeAllObjects]之前

if ([self.topicsArray containsObject:indexPath]) 
{ 
    [self.topicsArray removeObject:indexPath]; 
} 
else 
{ 
    [_topicsArray addObject:indexPath]; 

} 
相关问题