Ios 无法使用自定义单元格更改某些属性

Ios 无法使用自定义单元格更改某些属性,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我正在为我的应用定制一个UITableViewCell,一切都很顺利,因为我已经做了好几次了 现在我想做一些动画和问题来了 我将尽可能简短地解释: 我正在做一个字典应用程序。我有一个视图,其中包含一个带有自定义单元格(NTNHistoryCell)的UITableView,该视图用于显示用户研究的历史记录 #import <UIKit/UIKit.h> #import "HistoryItem.h" @protocol NTNHistoryCellDelegate; @interf

我正在为我的应用定制一个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
它与所有的代码都不兼容,你可以看到我的评论,我可以改变背景颜色,但是UILabel的文本和frontView的框架

我打算向左移动,然后向右移动前视图

我哪里出错了

以下是我的截图,以澄清我的话(我没有足够的声誉来发布图片):

编辑: 我解决了。
请参阅@danypata reply中的我的评论。

因此,您需要检测表视图何时完成加载过程,然后为第一个可见单元格制作动画。因此,我的方法如下:

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

我不能100%确定这种方法是否有效,但您应该尝试一下。

您使用的是自动布局吗?@danypata不,我没有,我在所有的xib中都关闭了它!让我直截了当地说,您想在显示单元格时从表视图中设置第一个可见单元格的动画吗?@DanyData是的,这就是我想做的。@DanyData不完全是在显示单元格时,我只想设置一次动画,因为包含表视图的视图已加载。您好。对不起,我迟到了。我对你的代码做了一些尝试,但在我做了一些技巧并且一切正常之前,它仍然不起作用!。我使用[self-PerformManization:@selector(PerformManization)with object:nil afterDelay:0.0]而不是通过[self-PerformManization]调用该方法。真的不知道为什么。。。谢谢你的帮助!:)
-(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
   }];
}