我有包含自定义单元格的tableview。 当用户单击该行时,每个单元格都有我要翻转的视图。我成功地为这个工作了。但我挣扎的一点是当用户点击其他行时,我想翻回原来的视图查看前一个单元格并翻转当前单击的行。
这是一些代码
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
CustomCell *selectedCell =
(CustomCell *)[self.AlbumViewTable cellForRowAtIndexPath:self.current_index];
//if other row is already flipped then make it back to original state.
if(otherRowIsFlipped){
selectedCell.defaultImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"defaultIndecator.jpg"]];
selectedCell.defaultImage = CGRectMake(0, 0, 43, 43);
[self flipView:selectedCell.flipViewContainer From:selectedCell.activity To:selectedCell.defaultImage];
}
CustomCell * new_row =
(CustomCell *)[self.AlbumViewTable cellForRowAtIndexPath:indexPath];
new_row.activity = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
new_row.activity.frame = CGRectMake(0, 0, 43, 43);
[new_row.activity startAnimating];
//this method is merely called UIView subroutine to flip between two view
[self flipView:new_row.flipViewContainer From:new_row.defaultImage To:new_row.activity];
[self.AlbumViewTable deselectRowAtIndexPath:indexPath animated:YES];
}
我能够翻转先前选择的行并翻转当前选定的行,但是当我向下滚动tableview并翻转视图出现在从未被选中的行时,我发现了奇怪的事情。
我试图在CustomCell类中创建属性并试图翻转,但也没有运气。 我不确定这种方法是否正确,但除非我向下滚动,否则它似乎有效 加载其他行。
我很感激任何建议。谢谢
答案 0 :(得分:1)
您应该使用这样的视图结构制作自定义UITableViewCell
-CELL
--CONTENT_VIEW
---1st_side
---2nd_side
,代码是
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.7f];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:containerView cache:NO];
[firstView removeFromSuperview];
[containerView addSubview:secondView];
[UIView commitAnimations];
和后方法相同