繁体   English   中英

iOS7中所选UITableViewCell的奇怪行为

[英]Strange Behaviour of Selected UITableViewCell in iOS7

我正在将我的应用程序移植到iOS 7,并且我的tableViews有一些奇怪的行为。 当我选择一个单元格时,分隔符没有明显的原因消失 不仅如此, 所选状态背景图像也向上移动约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,所选BG图像略高):

    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;

我遇到了类似的问题,为我修复它的方法是覆盖UITableViewCell子类中的layoutSubviews,如下所示:

- (void)layoutSubviews
{
    [super layoutSubviews];
    self.selectedBackgroundView.frame = self.backgroundView.frame;
}

重要的是首先调用[super layoutSubviews]

顺便说一句,我认为默认行为是在iOS7中。 如果您查看Apple Mail应用程序,您会看到选择单元格时分隔线也会消失,并且活动背景将被绘制为分隔线所在的位置。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM