gpt4 book ai didi

iphone - 移动 UITableView 行然后选择它后,它仅在边缘变成蓝色

转载 作者:行者123 更新时间:2023-12-03 19:08:53 26 4
gpt4 key购买 nike

我有一个带有可重新排序行的 UITableView ,并且我使用标准 UITableViewCell.text 属性来显示文本。当我点击“编辑”、移动一行、点击“完成”,然后点击该行时,内置 UILabel 变为完全白色(文本和背景)且不透明,并且单元格的蓝色阴影不会变化显示在它后面。是什么赋予了?有什么事情是我应该做但我没有做的吗?我有一个 hacky 修复程序,但我想要真正的 McCoy。

以下是重现它的方法:

从 iPhone OS 2.2.1 SDK 中的标准“基于导航的应用程序”模板开始:

  1. 打开RootViewController.m

  2. 取消注释 viewDidLoad,并启用“编辑”按钮:

    - (void)viewDidLoad {
    [super viewDidLoad];
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    self.navigationItem.rightBarButtonItem = self.editButtonItem;
    }
  3. 指定表格有几个单元格:

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 4;
    }
  4. tableView:cellForRowAtIndexPath:中,添加一行来设置单元格的文本属性,从而使用内置的 UILabel subview :

    // Set up the cell...
    cell.text = @"Test";
  5. 要启用重新排序,请取消注释 tableView:moveRowAtIndexPath:toIndexPath:。默认实现是空白的,在本例中这很好,因为模板不包含数据模型。

  6. 为模拟器、操作系统 2.2.1、构建并运行配置项目。当应用程序出现时,点击“编辑”,然后将任意行滑动到新位置,点击“完成”,然后一次点击每一行。通常,点击会选择一行,将其变为蓝色,并将其文本变为白色。但是,点击刚刚移动的行会导致 UILabel 的背景颜色变为白色。结果是一个令人困惑的白色开放空间,边缘有蓝色 strip 。奇怪的是,在第一次虚假点击后,另一次点击似乎解决了问题。

到目前为止,我已经找到了修复该问题的 hack,但我对此并不满意。它的工作原理是确保内置 UILabel 在选择后立即不透明并且没有背景色。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// hacky bugfix: when a row is reordered and then selected, the UILabel displays all crappy
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
for (UIView *view in cell.contentView.subviews) {
if ([[view class] isSubclassOfClass:[UILabel class]]) {
((UILabel *) view).backgroundColor = nil;
view.opaque = NO;
}
}

// regular stuff: only flash the selection, don't leave it blue forever
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}

这似乎有效,但我不认为它永远是一个好主意。解决这个问题的正确方法是什么?

最佳答案

这看起来像是 UITableView 渲染中的错误,您应该就此提交 Radar 错误报告。就像移动后单元格没有正确刷新一样。

目前解决此问题的一种方法是不使用内置标签,而是在单元格中使用自己的标签:

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

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];

CGRect frame = cell.contentView.bounds;
frame.origin.x = frame.origin.x + 10.0f;

UILabel *textLabel = [[UILabel alloc] initWithFrame:frame];
[textLabel setAutoresizingMask:UIViewAutoresizingFlexibleRightMargin];
textLabel.tag = 1;
textLabel.textAlignment = UITextAlignmentLeft;
textLabel.backgroundColor = [UIColor clearColor];
textLabel.textColor = [UIColor blackColor];
textLabel.font = [UIFont boldSystemFontOfSize:20.0];
textLabel.numberOfLines = 1;
textLabel.highlightedTextColor = [UIColor whiteColor];
[cell.contentView addSubview:textLabel];
[textLabel release];

}

UILabel *textLabel = (UILabel *)[cell viewWithTag:1];
textLabel.text = @"Test";

return cell;
}

我尝试了这个,它没有显示出与内置标签相同的白色空白矩形。但是,向表格单元格添加另一个非不透明 View 可能不是整体渲染性能的最佳选择。

我不知道这是一个多么严重的故障,因为苹果不希望你在表格行上保留选择突出显示(他们最近在审查过程中一直在强制执行这一点)。您应该打勾或通过选择移动到导航层次结构中的下一个级别,此时此白框只会在屏幕上显示一小会儿。

关于iphone - 移动 UITableView 行然后选择它后,它仅在边缘变成蓝色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/564420/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com