【发布时间】:2017-09-28 11:44:13
【问题描述】:
我的应用程序在 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;
}
【问题讨论】:
标签: ios objective-c uitableview animation uibutton