【发布时间】:2013-11-06 18:38:17
【问题描述】:
我有一个自定义按钮,按下时图像会发生变化。此按钮位于 UITableView 内 UITableViewCell 的 contentView 中。
在图像更改之前按下按钮会有明显的延迟。将按钮从单元格中取出并放入 UIView 中,按下时图像的变化是即时的。
如何消除这种延迟?
值得指出的是,我已经尝试在 UITableView 上设置 delaysContentTouches,但我可以看到它没有任何区别。
这里有一些测试代码可以证明这个问题。创建新项目并将 UITableView 添加到情节提要。
#import "JWViewController.h"
@implementation JWViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.delaysContentTouches = NO;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; }
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 1; }
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return return 65.0f; }
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [[UITableViewCell alloc] init];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:@"apple"] forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:@"apple_selected"] forState:UIControlStateHighlighted];
button.frame = CGRectMake(0, 0, 65, 65);
[cell.contentView addSubview:button];
return cell;
}
@end
我已经搜索过,似乎有很多 other posts 与此相关,但没有一个有效的答案。
This blog post 在这种简单的情况下似乎也不起作用。
【问题讨论】:
-
它可以在 iOS 6 上运行吗?当我写那篇文章时,iOS 7 并不存在。 :o) 我去看看...
-
为 6 编译了我的测试应用程序,但我仍然得到延迟。
-
您是否尝试记录
didSelectRowAtIndexPath和touchesShouldCancelInContentView的时间?也许这会给你一个线索,让你知道事情可能会延迟。 -
@JMWhittaker :我已经在类似问题上发布了an answer
-
@staticVoidMan 谢谢你看看
标签: ios objective-c uitableview uibutton