2013-06-12 2 views
2

내 앱용 UITableViewCell을 사용자 정의하고 있는데 여러 번 해봤 기 때문에 모든 것이 잘됩니다.사용자 정의 셀을 사용하여 일부 속성을 변경할 수 없습니다.

이제 애니메이션을 몇 개 만들고 문제를 해결하려고합니다.

나는 가능한 한 짧은 설명 할 것이다 : 내가 사전 응용 프로그램을하고 있어요

. 내 사용자 지정 셀 (NTNHistoryCell) 함께 UITableView 포함하는보기가,이보기는 사용자의 연구 기록을 표시하기위한 것입니다.

#import <UIKit/UIKit.h> 
#import "HistoryItem.h" 

@protocol NTNHistoryCellDelegate; 
@interface NTNHistoryCell : UITableViewCell<UIGestureRecognizerDelegate> 

@property (strong, nonatomic) HistoryItem *historyItem; 

@property (strong, nonatomic) IBOutlet UILabel *lblWord; 
@property (strong, nonatomic) IBOutlet UILabel *lblDictName; 
@property (strong, nonatomic) IBOutlet UILabel *lblTimeStamp; 

//variables for editing 
@property (strong, nonatomic) IBOutlet UIImageView *imgDeleteBackground; 
@property (strong, nonatomic) IBOutlet UIView *frontView; 
@property (strong, nonatomic) UIImageView *imgIconDelete; 

@property (strong, nonatomic) id<NTNHistoryCellDelegate> delegate; 

-(void)initLabels; 
@end 

@protocol NTNHistoryCellDelegate <NSObject> 

@optional 

-(void)historyCellIsDeleted:(NTNHistoryCell*)historyCell; 

@end 

사용자는 왼쪽 또는 항목을 삭제 오른쪽으로 스 와이프 할 수 있습니다. 셀에 중요한 두 가지 사항이 있습니다. 사용자가 스 와이프하는 동안 색상을 변경하는 UIImageView와 같은 배경, UILabels이 포함 된 UIView로 frontView, 사용자가 스 와이프하는 동안 frontView가 프레임을 변경합니다. 사용자가 번역본을 스 와이프하면 셀이 삭제됩니다 (해당 항목은 데이터베이스에서도 삭제됩니다).

이제 테이블 뷰가로드 될 때마다 셀을 스 와이프 할 수 있음을 알리는 애니메이션을 만들고 싶습니다. 나는 아래의 코드로 이벤트 didEndDisplayingCell을 사용 : 그것은 모든 코드와 잘려고하고 있지 않다

-(void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    //do cell animation to inform user that the cell can be swiped to delete 
    //only for the 1st row  
    if(indexPath.row == ((NSIndexPath*)[[tableView indexPathsForVisibleRows] lastObject]).row) 
    {   
     NTNHistoryCell *cell = (NTNHistoryCell *)[tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]; 
     CGRect originalFrame = cell.frontView.frame; 
     [UIView beginAnimations:@"move" context:nil]; 
     [UIView setAnimationDuration:1.0]; 

     //move left 

     //not working! 
     cell.frontView.frame = CGRectMake(-originalFrame.size.width, originalFrame.origin.y, originalFrame.size.width, originalFrame.size.height); 
     cell.lblWord.text = @"text change test";//not working! 
     cell.lblDictName.text = @"text change test";//not working! 
     cell.frontView.backgroundColor = [UIColor greenColor];//work fine! 

     [UIView commitAnimations]; 
    } 
} 

, 당신은 내가 배경색하지만 UILabel의 텍스트 및 FrontView에의 프레임을 변경할 수 있습니다, 내 댓글을 볼 수 있습니다.

왼쪽으로 이동 한 다음 frontView를 오른쪽으로 이동하려고합니다.

어디서 잘못 되었나요? http://i.stack.imgur.com/dUddJ.png

편집 : 내가 그것을 해결 여기

은 내 말을 명확하게하기 위해 스크린 샷 (I 이미지를 게시하기에 충분한 평판을 가지고하지 않은 경우)입니다. @danypata 답장에 대한 내 의견보기.

+0

자동 레이아웃을 사용하고 있습니까? – danypata

+0

@danypata 아니, 나는 모든 xib를 위해 그것을 끈다! –

+0

이렇게하면 직선이됩니다. 셀이 표시 될 때마다 테이블보기에서 첫 번째 보이는 셀에 애니메이션을 적용하겠습니까? – danypata

답변

1

그래서 테이블 뷰가로드 프로세스를 완료하고 첫 번째 보이는 셀에 대한 애니메이션을 수행하면이를 감지해야합니다. 그래서 여기에 내 접근 방식입니다 :

-(void)viewDidLoad { 
    [super viewDidLoad]; 
    shouldAnimate = YES; 
} 

//delegate method 
-(void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath 
{ if(shouldAnimate) { 
     if([indexPath row] == ((NSIndexPath*)[[tableView indexPathsForVisibleRows] lastObject]).row){ 
     //now the table view completes the loading process 
     [self perforAnimation]; 
    } 
} 

-(void)performAnimation { 
    shouldAnimate = NO; 
    NSIndexPath *firstCelPath = [[yourTableView indexPathsForVisibleCells] objectAtIndex:0] 
    YourCustomCell *cell = [yourTableView cellForRowAtIndexPath:firstCellPath]; 
    [UIView animateWithDuration:0.3 animations:^{ 
    //do your changes 
    }]; 
} 

나는이 접근 방식이 효과가있을 것이라고 확신하지는 않지만 시도해보십시오.

+0

안녕하세요. 늦어서 죄송합니다. 나는 코드를 가지고 시도해 보았지만 여전히 약간의 트릭을 할 때까지는 작동하지 않는다. 메서드를 다음과 같이 호출하는 대신 : [self performAnimation] 나는 self performSelector : @selector (performAnimation) withObject : nil afterDelay : 0.0]을 사용합니다. –

+0

정말 이유를 모르겠다 ... 도와 줘서 고마워! :) –

관련 문제