2013-05-15 51 views
0

我有一个自定义UITableViewCell,其中包含一个UIButton,并且该单元本身响应UIControlEventTouchUpInside。单元格的行为应该与iPhone模拟器以及iPhone5的iPhone EXCEPT的所有版本一样。出于某种原因,在iPhone5上,电池只响应电池底部的触摸。事实上,对于用户来说,实际让单元对触摸做出响应是非常困难的,为了得到它的响应,他们必须在单元底部附近多次点击。而且,UIButton在iPhone5上完全没有响应。我还应该补充说,这个错误只发生在应用程序经过优化以适应iPhone5的较大视网膜屏幕之后。我倾向于认为这与单元格的大小有关,但它在iPhone 5上的外观看起来应该完全一样。我也尝试通过创建一个单独的NIB来实例化当iPhone5被使用时利用“自动布局”界面生成器功能来解决此问题,但这没有解决。自定义UITableViewCell限制iPhone5上的用户触摸响应

下面是instatiates在ViewController.m自定义的UITableView单元代码:

// 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; 
    }... 

这里是为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 

回答

1

听起来像一个问题包含单元格的表视图的超级视图的自动调整大小(不是单元格本身,也可能不是表格视图)。检查所有视图是否自动调整大小或在代码中调整大小以利用完整的可用高度。您还可以在显示单元格时添加断点(tableView:didEndDisplayingCell:forRowAtIndexPath:),然后使用gdb调查高级视图及其框架(po [cell superview])。

+0

谢谢!就是这样! –

相关问题