2016-01-21 29 views
1

我正在做一个UITableView与iOS应用程序的可展开/可折叠单元格,我想显示,当用户点击单元格图像将下来,当再次点击它时,图像将是这样的,这是可能的! 这里是我的代码如何在ios中的单元格上单击时在可展开单元格中旋转图像?

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
if (selectedIndex == indexPath.row) 
{ 
    selectedIndex = -1; 
    [myContestTableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; 
    return; 
} 
if (selectedIndex != -1) 
{ 
    NSIndexPath *prevPath = [NSIndexPath indexPathForRow:selectedIndex inSection:0]; 
    selectedIndex = indexPath.row; 
    [myContestTableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:prevPath] withRowAnimation:UITableViewRowAnimationFade]; 
} 
    selectedIndex = indexPath.row; 
    [myContestTableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; 

} 

在此我的形象的名字叫“rotataeImage”请帮助我。 这里是我膨胀的室默认的图像就像是在细胞这个

enter image description here

当用户点击图像会,并再次对细胞的默认图像用户点击将在这里显示

+0

请解释的困难,你面对 –

+0

查看更新的问题。谢谢:) –

回答

2

如果你继承你可以使用UITableViewCellsetSelected: animated:,在那里添加你的配置。

- (void)setSelected:(BOOL)selected animated:(BOOL)animated 
{ 
    [super setSelected:selected animated:animated]; 

    YOURIMAGEVIEW.transform = CGAffineTransformMakeRotation(selected ? M_PI : 0); 

    // Configure the view for the selected state 
} 

如果不是,您只需使用这里面-cellForRowAtIndexPath像:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    ... 
    YOURTABLECELL.yourImageView.tranform = CGAffineTransformMakeRotation((selectedIndex == indexPath.row) ? M_PI : 0); 
    ... 

    return tableCell; 
} 
+1

谢谢@Oyeoj它工作正常:) –

+0

@MangiReddy,你可以把它标记为正确的答案..;)很高兴帮助。干杯! – 0yeoj

+0

雅肯定我已经做到了:) –

相关问题