2014-09-19 50 views
1

这个问题让我坚持了一段时间,我无法为我的生活看到它为什么会发生。UITableViewCell在UITableViewCell中使用不同的约束条件刷新

我有一个tableView与自定义单元格里面。该单元格左上角有一个imageView,然后是从plist中查找的各种信息。我正在使用自动布局来设置所有元素的位置。我已刷新所有约束,以便全部更新。请看下图:当我滚动视图向下和细胞熄灭屏幕出现

enter image description here

的问题。每次他们会被刷新,我都会把他们取出。

BSettingsCell * cell = [tableView_ dequeueReusableCellWithIdentifier:bSettingsCellIdentifier]; 

当他们刷新尽管他们现在绑定的约束现在不工作。 imageview是60x60像素,图像是120x120像素,并命名为[email protected]以考虑视网膜屏幕。

enter image description here

我已经把一个红色边框的图片周围,使其更容易地看到发生了什么。正如您所看到的,由于某种原因,刷新后图像正在向下移动。

我试过切换到框架布局来修复它的位置,这是行不通的。

我找到this stackoverflow问题似乎提出了同样的问题,但只提出它作为一个问题,而不是帮助解决问题。

任何帮助将不胜感激,因为我不喜欢用keeplayout重写所有的代码,如果有一个简单的方法来解决它。

编辑:

这里是我的cellForRowAtIndex方法:

- (UITableViewCell *)tableView:(UITableView *)tableView_ cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    BSettingsCell * cell = [tableView_ dequeueReusableCellWithIdentifier:bSettingsCellIdentifier]; 

    NSDictionary * dict = [_settingsData objectForKey:_settingsPacks[indexPath.row]]; 

    cell.nameLabel.text = [dict objectForKey:bSettingsName]; 
    cell.byLabel.text = [dict objectForKey:bArtist]; 
    cell.stickerImageView.image = [UIImage imageNamed:[dict objectForKey:bImage]]; 

    // To make it obvious that the view is changing position 
    cell.stickerImageView.layer.borderColor = [UIColor redColor].CGColor; 
    cell.stickerImageView.layer.borderWidth = 2; 

    cell.descriptionView.text = [dict objectForKey:bDescription]; 

    [cell.linkButton setTitle: [dict objectForKey:bLink] forState: UIControlStateNormal]; 
    cell.linkButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; 

    cell.selectionStyle = UITableViewCellSelectionStyleNone; 

    return cell; 
} 

,也的自动布局约束在XIB文件中的截图:(注意:虽然在屏幕截图的名字不包括和通过标签被保持与约束细)

enter image description here

+0

任何人的图像视图顶部空间和领先的空间,它的父? – danh 2014-09-19 00:11:17

+0

那么,你是说你的图像视图的属性名称不是imageView(这是你提供的链接中提到的问题)? – rdelmar 2014-09-19 00:18:42

+0

是顶级空间超级查看是8和领先空间superview是6.这两个和宽度和高度等于60是四个约束 – 2014-09-19 00:19:43

回答

0

虽然这个解决方案非常平凡,但确实对我有帮助,所以我会在这里发布。

基本上,解决方案是删除我所做的并将其添加到每个步骤中。尽管最终它看起来完全一样。我认为有时候会有一些蠕虫进入Xcode并导致问题。通常重新设置工作会解决这些问题。

当试图解决这个问题时,我假设错误在我的代码中,并且我可能花了太长时间试图找到错误。最后花几分钟时间重做它a)通常可以让你看到错误,因为你可以看到你犯的错误b)它可以重置由Xcode引起的任何错误。

希望这有助于具有类似的挫折在未来

1

您是否尝试过使用

BSettingsCell * cell = [tableView_ dequeueReusableCellWithIdentifier:bSettingsCellIdentifier forIndexPath: indexPath]; 

取而代之?

+0

这似乎没有任何区别 – 2014-09-19 06:27:47

相关问题