これは簡単な問題のように思えますが、解決策を見つけるためにレンガの壁にぶつかりました。ここにいる誰かが助けてくれることを願っています...
UITableViewStyleGroupedを使用してUITableViewを作成していますが、テーブルビューのすべてのセクションの最初の行と2番目の行の間に小さな(1ピクセル)白い線が表示されています(画像を参照)
この線の理由は、各セクションの最初のセルが他のセクションより1ピクセル高いためと思われます。各グループの最初のセルの高さを29ピクセル(他のセルは30ピクセル)に設定すると、ギャップがなくなり、すべてが正常になります。
これは回避策は成功していますが、厄介なハックの使用を避けることができるように、これが発生する理由を知りたいと思います。
ご参考までに:
- 使用して、これが背景画像の問題ではないことを確認しました。これらはすべて30ピクセルの高さであり、同じ結果になる上部の画像を中央の画像に置き換えました。
- 私はseparatorStyle=UITableViewCellSeparatorStyleNoneを設定することにより、セル間のすべての境界線を削除しました
- この効果はUITableViewStylePlainでは発生しません
どんな助けでも大歓迎です。
ありがとう
テーブル設定のコード:
myTable = [[UITableView alloc] initWithFrame:CGRectMake(TABLE_SHIFT_OFFSET,
DATE_SLIDER_HEIGHT - DATE_SLIDER_SHADOW_HEIGHT,
326,
self.view.frame.size.height - DATE_SLIDER_HEIGHT + DATE_SLIDER_SHADOW_HEIGHT) style:UITableViewStyleGrouped];
myTable.backgroundColor = [UIColor clearColor];
myTable.backgroundView = nil;
myTable.separatorStyle = UITableViewCellSeparatorStyleNone;
[self.view addSubview:myTable];
myTable.dataSource = self;
myTable.delegate = self;
セル設定のコード:
- (float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
// This is a hack to make sure that a white line doesnt appear between the
// first and second rows in the table, which happens for reasons I dont understand
if (indexPath.row == 0) {
return 29;
}
return 30;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
MyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"satCell"];
if (!cell)
{
cell = [[MyTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"satCell"];
}
cell.backgroundView = nil;
cell.backgroundView = [[UIView alloc] initWithFrame:CGRectZero];
cell.backgroundColor = [UIColor whiteColor];
int numberOfRowsInThisSection = [self tableView:tableView numberOfRowsInSection:indexPath.section];
if (numberOfRowsInThisSection == 1)
{
cell.backingImage = self.singleWhite;
}
else if (indexPath.row == 0)
{
cell.backingImage = self.topWhite;
}
else if (indexPath.row % 2 == 0)
{
// Even row
if (indexPath.row == numberOfRowsInThisSection - 1)
{
// Last row (even)
cell.backingImage = self.botWhite;
}
else
{
// Normal row (even)
cell.backingImage = self.midWhite;
}
}
else if (indexPath.row % 2 == 1)
{
// Odd row
if (indexPath.row == numberOfRowsInThisSection - 1)
{
// Last row (even)
cell.backingImage = self.botDark;
}
else
{
// Normal row (odd)
cell.backingImage = self.midDark;
}
}
// Setup cell text [REMOVED FOR BREVITY]
return cell;
}
MyTableViewCell内でバッキングイメージを設定するためのコード:
- (void)setBackingImage:(UIImage *)backingImage
{
if (self.backingImage != backingImage)
{
_backingImage = nil;
_backingImage = backingImage;
self.backingView.image = backingImage;
}
}
self.backingViewは、次のコードを使用して設定されます。
[[UIImageView alloc] initWithFrame:CGRectMake(7, 0, 307, 30)];