我正在将我的应用程序移植到 iOS 7 平台,并且在我的 tableView 中遇到了一些奇怪的行为。当我 选择一个单元格时,分隔符会出现无法解释的消失。不仅如此,选中状态的背景图片也会向上移动约 1 像素,尽管其框架并未指示此问题。在 iOS 6 或更早的操作系统中我没有遇到这些问题。
我按照以下方式定义了我的表视图:
statisticsTableView = [[UITableView alloc] initWithFrame:CGRectMake(170.0f, 0.0f, 150.0f, window.size.height) style:UITableViewStylePlain];
statisticsTableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background.png"]];
statisticsTableView.separatorColor = [UIColor darkGrayColor];
//statisticsTableView.separatorInset = UIEdgeInsetsZero; // <- Makes app crash in iOS6 or older
statisticsTableView.showsHorizontalScrollIndicator = NO;
statisticsTableView.delegate = self;
statisticsTableView.dataSource = self;
这个单元格被子类化,相关的部分如下(正常和选中的背景图像大小完全相同,在iOS6或更早版本中显示正确,只有在iOS 7中选定的背景图像稍微高一些):
UIView *backgroundView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 150.0f, 70.0f)];
backgroundView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"cell_background_corp.png"]];
self.backgroundView = backgroundView;
UIView *backgroundView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 150.0f, 70.0f)];
backgroundView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"cell_background_corp_selected.png"]];
self.selectedBackgroundView = backgroundView;
现在,我知道其他人已经提出了这个问题(或者至少其中的一部分),但是那里的答案都没有对我起作用。供参考,我尝试过这些“解决方案”,它们都没有起作用:
Putting this into my didSelectrowAtIndexPath made my cells deselect.
But, I need my selected cell to stay selected, and besides
it looked really awkward with the blinking as swithces between states:
[self.tableView deselectRowAtIndexPath:indexPath animated:NO];
[self.tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
另一个:
Putting this into the heightForRowAtIndexPath delegate method
as a return value did absolutely nothing:
ceilf(rowHeight);
最后:
This was my attempt to fix the background image position bug. I modified
the way I added the selected background view in the subclassed tableView cell,
but it did not do squat:
UIView *backgroundView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 150.0f, 70.0f)];
if (iOSVersion >= 7.0f)
{
backgroundView.frame = CGRectMake(0.0f, 1.0f, 150.0f, 70.0f);
}
backgroundView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"cell_background_corp_selected.png"]];
self.selectedBackgroundView = backgroundView;