2016-08-08 4 views
0

오늘 내 앱에서 문제가 발생했습니다. View Controller 내부에 테이블이 있습니다. 문제가 발생하면 Compare 버튼을 탭합니다. 비교 버튼을 누르면 작은 애니메이션이 발생하고 모든 셀의 크기가 조정되어 selected 또는 not selected 이미지가 표시됩니다. https://www.youtube.com/watch?v=6SkIbp1xf0E일부 표 셀이 표시되지 않습니다.

문제는 모든 CELS 기본 not selected 버튼을해야하지만, 일부 세포가 표시된 이미지를 얻을하지 않습니다 것입니다 : 여기

문제가있는 동영상입니다.

내 코드는 다음과 같습니다.

//animate function 
-(void)animate{ 
[[tableView visibleCells] enumerateObjectsUsingBlock:^(CustomCell *cell, NSUInteger idx, BOOL *stop) 
{ 
    [cell.myImageView setFrame:CGRectMake(cell.frame.size.width * 0.15 + 
cell.myImageView.frame.origin.x, cell.myImageView.frame.origin.y + 
cell.frame.size.height * 0.1, cell.myImageView.frame.size.width * 1.25, 
cell.myImageView.frame.size.height * 1.25)]; 

    completion:^(BOOL finished) 
    { 
    // code to execute when the animation finishes 
    [UIImageView animateWithDuration:1 animations:^{ 
    //select button animation 
    cell.compareProduct.image = [UIImage imageNamed:@"deselectedProduct.png"]; 
    cell.compareProduct.hidden = false; 
    [cell.compareProduct setAlpha:0]; 
    [UIImageView beginAnimations:NULL context:nil]; 
    [UIImageView setAnimationDuration:1.0]; 
    [cell.compareProduct setAlpha:1]; 
    [UIImageView commitAnimations]; 
    }];} 
} 

이 코드 덩어리는 매번 완벽하게 실행됩니다. 내가 본 모든 셀에는 selected \ not selected 버튼이 표시됩니다. 문제는 스크롤 할 때 발생합니다.

-(void)tableView:(UITableView *)theTableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{   
if (compareActive) //if compare button was pressed 
{ 
[[tableView visibleCells] enumerateObjectsUsingBlock:^(CustomCell *cell, NSUInteger idx, BOOL *stop) { 
CGRect someRect = CGRectMake(cell.frame.size.width * 0.15 + 
cell.myImageView.frame.origin.x, cell.myImageView.frame.origin.y + 
cell.frame.size.height * 0.1, cell.myImageView.frame.size.width * 1.25, 
cell.myImageView.frame.size.height * 1.25); 
[cell.myImageView setFrame:someRect]; 

// i was forced to place another moving animation so the user won't notice how the image jumps from the old frame to the new frame 
[cell setFrame:CGRectMake(cell.frame.size.width, cell.frame.origin.y, cell.frame.size.width, cell.frame.size.height)]; 
[UIView animateWithDuration:1 animations:^{ 
[cell setFrame:CGRectMake(0, cell.frame.origin.y, cell.frame.size.width, cell.frame.size.height)]; 
}];} 
} 

왜 일부 세포는 selectednot selected 표시가없는 이유 프레임 점프? 또한 CustomCell을 사용하고 있다는 것을 잊지 마십시오.

더 나은 솔루션이나 다른 기능을 사용하려면 저에게 알려주십시오. 원하는 기능은 다음과 같습니다. compare 버튼을 누르면 모든 테이블 셀이 한 번에 프레임을 변경합니다.

미리 감사드립니다.

답변

0

나는 [tableView visibleCells]willDisplayCell: 기능이 서로 잘 맞지 않는다고 생각합니다.

[tableView visibleCells]으로 전화를 걸면 즉시 세포 발사 willDisplayCell:이 반환되지 않을 수 있습니다.

ViewController에서 bool 변수를 사용하고 테이블보기를 cellForViewAtIndexPath:을 통해 다시로드하는 동안 봐야합니다. 그리고 나서 사용자가 비교 버튼을 클릭하면 reloadData으로 전화하십시오.

관련 문제