动画按钮在UITableViewCell中不可见

时间:2017-09-28 11:44:13

标签: ios objective-c uitableview animation uibutton

我的应用程序在UITableView中有一个服务器列表,其中显示了您是否使用图像连接到服务器。目前,静态图像处理正常。

我现在想要添加一个非常基本的动画,表明它正在连接到服务器。只需在“已连接”和“已断开连接”的图像之间闪烁。

但是当我将按钮的图像设置为动画时,它根本不显示任何内容,而不是动画的任何帧,而不是表格单元的默认图像,只是空白。创建这样的动画适用于视图中不在表中的按钮,因此创建动画不是问题。当按下按钮时它会开始播放,让我觉得按钮只需要刷新或强制重绘。但是我找不到任何东西。

我使用reloadData重新加载我的表。

(简体)ServerCell.h的来源:

@interface ServerCell : UITableViewCell 

    @property (nonatomic, strong) IBOutlet UILabel *nameLabel;
    @property (nonatomic, strong) IBOutlet UILabel *ipLabel;
    @property (nonatomic, strong) IBOutlet UIImageView *serverImageView;
    @property (weak, nonatomic) IBOutlet UIButton *mConnectionBtn;

@end

ServerCell.m

@implementation ServerCell

#pragma mark - Properties

@synthesize nameLabel;
@synthesize ipLabel;
@synthesize serverImageView;
@synthesize mConnectionBtn;

#pragma mark - Constructor/Destructor 

/////////////////////////////////////////////////////////////////
/*
 * Class constructor
 */
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
    }
    return self;
}

#pragma mark - Class Methods

/////////////////////////////////////////////////////////////////
/*
 * Communicate to the superview the user selection
 */
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
}

@end

的cellForRowAtIndexPath:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Cast the TableCell to a custom ServerCell
    ServerCell *cell = (ServerCell *)[tableView dequeueReusableCellWithIdentifier:@"ServerCell"];

    [cell.mConnectionBtn addTarget:self action:@selector(ActionServerCell:) forControlEvents:UIControlEventTouchUpInside];

    NSArray* images = [NSArray arrayWithObjects:[UIImage imageNamed:@"connected.png"], [UIImage imageNamed:@"disconnected.png"], nil];
    UIImage* anim = [UIImage animatedImageWithImages:images duration:1.0];

    [cell.mConnectionBtn setImage:anim forState:UIControlStateNormal];

    // return the cell object
    return cell;
}

2 个答案:

答案 0 :(得分:0)

要显示正在运行的流程,您只需添加activityIndicator而不是图片。

它可能比设置动画图像更简单。

  1. 将它连接到你的xib:
  2. @property (weak, nonatomic) IBOutlet UIActivityIndicatorView *activityIndicator;

    1. 如果你不需要它只需在你的cell.m中设置:
    2. cell.activityIndicator.hidden = YES;

      1. 然后当您的流程正常运行时,请启用它:
      2. self.activityIndicator.hidden = NO;

        如果我错了或者我错过了这个问题,请告诉我:))

答案 1 :(得分:0)

这应该做你想要的。调用开始动画时可能需要进行调整。

C:\Program Files (x86)\Windows Azure platform AppFabric\SDK\V1.0\Assemblies\NET4.0\Microsoft.ServiceBus.dll
相关问题