2015-02-07 67 views
0

我有一個靜態表格和3個單元格。我隨機在每個單元中放置一些標籤和其他控制器並運行它。它顯示很好。但是,當我放置一張圖像時,它一次只能覆蓋兩個或三個單元格。在UITableViewController我評論所有tableView方法。爲什麼發生這種情況?UIImage沒有正確定位在靜態單元格中

+0

「當我把圖像」 - 但你怎麼做?很明顯,你這樣做的方式是錯誤的。但是你不是在展示你在做什麼,那麼人們怎麼能夠「理解」它呢? – matt 2015-02-07 19:14:00

+0

Pease分享一些代碼,所以我們可以幫助你。如果您使用故事板或XIB設計您的單元格,請張貼它的一些截圖。 – Romain 2015-02-07 19:15:20

+0

拖放。沒有代碼。沒有CGRect。我現在不是正確的方式嗎? : -/ – Tulon 2015-02-07 19:28:59

回答

1
  1. 這聽起來像你正在使用靜態單元格與UITableViewDelegate方法從你的描述,這不加起來。您不需要爲靜態表視圖實現這些方法。
  2. 檢查您的細胞高度以及是否啓用了clipsToBounds
  3. 檢查您的UIImageView大小以及是否啓用了clipsToBounds
+0

感謝評論。我得到了解決方案。:) – Tulon 2015-02-08 08:53:06

0

我一直在尋找的是這樣的:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewCell *cell = [super tableView:tableView cellForRowAtIndexPath:indexPath]; 

    if ((indexPath.row)==0) 
    { 
     cell.accessoryType = UITableViewCellAccessoryNone; 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"one"]; 

     UIImageView *backgroundView =[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 170)]; 
     backgroundView.image=[UIImage imageNamed:@"default-cover-image.jpg"]; 

     [cell.contentView addSubview:backgroundView]; 
    } 
    if ((indexPath.row)==1) 
    { 
     cell.accessoryType = UITableViewCellAccessoryNone; 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"two"]; 

     UIImageView *backgroundView =[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 44)]; 
     backgroundView.image=[UIImage imageNamed:@"sectionHeader.png"]; 

     [cell.contentView addSubview:backgroundView]; 
    } 
    if ((indexPath.row)==2) 
    { 
     cell.accessoryType = UITableViewCellAccessoryNone; 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"three"]; 

     UIImageView *backgroundView =[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 44)]; 
     backgroundView.image=[UIImage imageNamed:@"sectionHeader2.png"]; 

     [cell.contentView addSubview:backgroundView]; 
    } 
    if ((indexPath.row)==3) 
    { 
     cell.accessoryType = UITableViewCellAccessoryNone; 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"four"]; 

     UIImageView *backgroundView =[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 170)]; 
     backgroundView.image=[UIImage imageNamed:@"default-cover-image.jpg"]; 

     [cell.contentView addSubview:backgroundView]; 
    } 

    return cell; 
} 

如果我只是剛落靜態表格單元格內的imageView,並在其中添加圖片,然後定位不準確的行動。雖然差異只出現在真實的設備上。不在故事板上。 感謝每一位評論我的帖子。祝你有美好的一天。 :)

相關問題