7

请看下面同一个应用程序中的3个表格视图单元格,界面生成器中单元格的高度为54,边框是在代码中使用CAShapeLayer创建的,高度为44。由于我在项目开发过程中从xcode5切换到xcode6,所以uitableviewcell 的一部分是在 xcode5 中创建的,一部分是在 xcode6 中创建的,还有一些单元格是在 xcode5 中创建的,后来在 xcode6 中进行了更改。

图 1。使用xcode5创建,所需的样式 uitableviewcell 内置在 xcode5 界面生成器中

图2。使用xcode6 beta6创建,iOS8模拟器显示,disclosure indicator错位,文字 偏移xcode6 beta6内置的uitableviewcell,在iOS8模拟器中显示

图 3。使用xcode6 beta6的 image2 的相同单元格,但在 iOS7.1 设备中运行,disclosure indicator放错 了位置xcode6 beta6内置的uitableviewcell,在iOS7.1设备中显示

我在界面生成器中比较了 uitableviewcell 的所有设置,发现没有差异。

而我对比了xxx.storyboard的源文件,终于得到了不同点:

case1 : 'tableViewCell' 标签,xcode5版本是:

<tableViewCell contentMode="scaleToFill" selectionStyle="none" accessoryType="disclosureIndicator" indentationWidth="10" reuseIdentifier="xxCell" rowHeight="54" id="far-Kn-fRP" customClass="xxCell">
  <rect key="frame" x="0.0" y="119" width="320" height="54"/>

case2 : 'tableViewCell' 标签,xcode6 beta6版本在下面,注意,创建新的 uitableviewcell 时缺少 < rect key="frame" ...>

<tableViewCell contentMode="scaleToFill" selectionStyle="none" accessoryType="disclosureIndicator" indentationWidth="10" reuseIdentifier="xxxCell" rowHeight="54" id="eav-sl-Yrd" customClass="xxxCell">

case3:image2和image3中的场景是在xcode5中创建的uitableviewcell,默认高度为44,在xcode6 beta6中修改高度为54,源码为:

<tableViewCell contentMode="scaleToFill" selectionStyle="none" accessoryType="disclosureIndicator" indentationWidth="10" reuseIdentifier="xxxCell" rowHeight="54" id="eav-sl-Yrd" customClass="xxxCell">
  <rect key="frame" x="0.0" y="119" width="320" height="44"/>

作为结论,似乎 xcode6 beta6 没有处理 .storyboard 文件中的 <rect key="frame" ...> 标签,并且会导致 uitableviewcell 错位。

补充:以上所有场景,代码都实现了heightForRowAtIndexPath,返回54。

我的问题是

  1. 我没有找到如何放置disclosure indicator在与 xcode5 相同的位置

  2. < rect key="frame" ...> 的缺失是一个错误还是被 xcode6 中的其他标签替换?可能与 iOS8 中的单元格自动调整大小功能有关?

  3. 是否有其他解决方案可以使 uitableviewcell 正确?我目前正在手动修改 .storyboard 文件以使用 xcode6 beta6 为每个新创建的 uitableviewcell 添加 < rect key="frame" ...> 标签,这很容易出错。

谢谢。

4

1 回答 1

0

About misplacing your border CAShapeLayer - you need to override layoutSubviews function of your custom cell class and update frame of layer accordingly.

Also don't use cell's bounds property, because it is a different than frame size:

- (void)layoutSubviews
{
    [super layoutSubviews];
    self.borderLayer.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
}

About offset for the disclosure indicator - I can't reproduce issue from your screenshot...

于 2014-12-15T14:34:51.043 回答