2013-05-15 52 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

謝謝!就是這樣! –

相關問題