简体   繁体   中英

ios 5 subview flip between two view in tableview cell

I have tableview which contains custom cell. Each cell has view that I want to flip when user click on that row. I successfully made it work for this one. But the point I struggle with is when user clicks on other row, I want to flip back to original view for previous cell and flip currently clicked row.

here is some code

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

I was able to flip back previously selected row and flip currently selected row, yet I found weird thing that when I scroll down tableview and flip view appeared on a row which has never been selected.

I tried to make properties in CustomCell class and attempted to flip but no luck too. I'm not sure this approach is correct but it seems to work unless I scroll down to load other rows.

I'd appreciate for any advices. Thanks

You should make a custom TableViewCell with such view structure

-CELL
--CONTENT_VIEW
---1st_side
---2nd_side

and the code is

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.7f];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:containerView cache:NO];
  [firstView removeFromSuperview];
  [containerView addSubview:secondView];
[UIView commitAnimations];

and the same for back method

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM