2016-01-21 34 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

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

相關問題