iOS 5 子视图在表视图单元格中的两个视图之间翻转



我有包含自定义单元格的表格视图。每个单元格都有我想在用户单击该行时翻转的视图。我成功地让它为这个工作。但是我挣扎的一点是,当用户单击另一行时,我想翻转回上一个单元格的原始视图并翻转当前单击的行。

这是一些代码

- (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];
}

我能够翻转回以前选择的行并翻转当前选定的行,但我发现奇怪的是,当我向下滚动表视图时,翻转视图出现在从未被选择的行上。

我试图在 CustomCell 类中制作属性并尝试翻转,但也没有运气。我不确定这种方法是否正确,但除非我向下滚动到加载其他行。

我将不胜感激任何建议。谢谢

你应该用这样的视图结构创建一个自定义的TableViewCell

-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];

和后法相同

最新更新