I have a custom button where the image changes upon a press. This button is in the contentView of a UITableViewCell within a UITableView.
There is a noticeable delay when pressing the button before the image changes. Take the button out of the cell and into a UIView the change of image on press is instant.
How do I remove this delay?
It's worth pointing out that I have tried setting delaysContentTouches on the UITableView but it makes no difference that I can see.
Here is some test code that proves the issue. Create new project and add a UITableView to the storyboard.
#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
I have searched and there appears to be a number of other posts relating to this but none with a working answer.
This blog post doesn't appear to work either in this simple case.