Reputation: 518
I have a custom UITableViewCell which contains a UIButton and the cell itself responds to UIControlEventTouchUpInside. The cell behaves as it should in the iPhone simulator and all versions of the iPhone EXCEPT for the iPhone5. For some reason, on the iPhone5, the cell only responds to touches at the very bottom of the cell. In fact, it is extremely difficult for the user to actually get the cell to respond to a touch, they have to tap many times near the bottom of the cell in order to get it to respond. Also, the UIButton simply does not respond at all on the iPhone5. I should also add that this error only started occurring AFTER the app was optimized to fit the iPhone5's larger retina screen. I'm inclined to believe that this has something to do with the sizing of the cell, but its appearance on the iPhone 5 looks exactly as it should. I also tried fixing this problem by creating a seperate NIB to instantiate when an iPhone5 is being used which takes advantage of the "Auto-layout" Interface Builder feature, but this solved nothing.
Here is the code that instatiates the Custom UITableView cell in the ViewController.m:
// Configure the cell...
switch (indexPath.section) {
case 0: // Full name
{
UINib *nib = [UINib nibWithNibName:@"ProfileNameCell" bundle:nil];
cell = [[nib instantiateWithOwner:nil options:nil] objectAtIndex:0];
[[(ProfileNameCell *)cell nameLabel] setText:[NSString stringWithFormat:@"%@ %@",
[[[Engine sharedInstance] currentUser] firstname],
[[[Engine sharedInstance] currentUser] lastname]]];
[[(ProfileNameCell *)cell imageButton] addTarget:self
action:@selector(selectUserPhoto:)
forControlEvents:UIControlEventTouchUpInside];
if ([[[Engine sharedInstance] currentUser] photoURL] != nil) {
[(ProfileNameCell *)cell setImageForURL:
[NSURL URLWithString:[[[Engine sharedInstance] currentUser] photoURL]]];
}
break;
}...
And here is the code for the View.m:
@implementation ProfileNameCell
@synthesize imageView=imageView_;
@synthesize imageButton;
@synthesize nameLabel;
- (void)awakeFromNib {
[(CALayer *)[self.imageView layer] setCornerRadius:5.0];
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code.
[(CALayer *)[imageView_ layer] setCornerRadius:5.0];
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state.
}
- (void)setImageForURL:(NSURL *)url {
[NSThread performBlockInBackground:^{
//Code that is executed when the UIButton is pressed...
}
- (void)dealloc {
[imageView_ release];
[imageButton release];
[nameLabel release];
[super dealloc];
}
@end
Upvotes: 0
Views: 154
Reputation: 119031
Sounds like a problem with the auto-resizing of a superview of the table view containing the cell (not the cell itself, and probably not the table view). Check that all of the views are automatically resizing or being resized in code to utilise the full available height. You can also add a breakpoint when the cell is displayed (tableView:didEndDisplayingCell:forRowAtIndexPath:
) and then use gdb to investigate the superviews and their frames (po [cell superview]
).
Upvotes: 1