2015-02-07 68 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,并在其中添加图片,然后定位不准确的行动。虽然差异只出现在真实的设备上。不在故事板上。 感谢每一位评论我的帖子。祝你有美好的一天。 :)

相关问题