gpt4 book ai didi

ios - 静态 UITableView 出现禁用的不透明 alpha 不起作用

转载 作者:行者123 更新时间:2023-11-29 03:48:36 25 4
gpt4 key购买 nike

我在 iOS 6.1 应用程序中有一个经典的 UITableViewController。 TableView 是静态的,在 Storyboard中设置,它意味着使用 UITableViewCellAccessoryCheckmark 作为 ON/OFF 开关来表示可配置的设置。 TableView 中有一个部分可以根据其他设置禁用另一个单元格。使用以下代码禁用单元格:

cell.userInteractionEnabled = NO;
cell.textLabel.backgroundColor = [UIColor clearColor];
cell.alpha = 0.4;

加载 TableView 后,代码就可以正常工作。

问题是加载 TableView 时,禁用的单元格代码无法正常工作,因为代码中的 alpha 设置不起作用。 UserInteractionEnabled 属性有效,但 alpha 设置无效。

这是在加载 View 时应禁用 UITableViewCell 的代码。

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell* cell = [super tableView:tableView cellForRowAtIndexPath:indexPath];

if (cell)
{
...

if ([[self currentSettingForIndexPath:indexPath] isEqualToString:@"myDependencySetting"])
{
...
cell.userInteractionEnabled = NO;
cell.textLabel.backgroundColor = [UIColor clearColor];
cell.alpha = 0.4;

NSLog(@"Disabling cell: %0.2f", cell.alpha);
...
}
else
{
cell.alpha = 1.0;
cell.userInteractionEnabled = YES;
}
}

NSLog(@"Cell alpha: %0.2f", cell.alpha);

return cell;
}

这里的代码相当简单,我向super询问cell(因为self是UITableViewController的子类,所以应该不是问题),然后配置cell。如果当前索引路径上的单元格取决于另一个设置,我会禁用该单元格(我删除了一些其他不相关的代码行)。

输出内容为:

...
Cell alpha: 1.00
...
Cell alpha: 1.00
Disabling cell: 0.40
Cell alpha: 0.40
Cell alpha 1.00
...

因此根据输出,单元格的 alpha 属性已正确设置。但单元格 alpha 未设置,但由于 userInteractionEnabled,单元格不可点击。

相同的代码可用于禁用 tableView 委托(delegate) didSelectRowAtIndex 中的单元格。

问题是:为什么以及什么可以覆盖单元格的 Alpha 值?

谢谢。

最佳答案

所以我知道已经过去了两年了,但我和你遇到了同样的问题,并偶然发现了这个问题。我碰巧使用的是 iOS 8,但问题似乎是一样的:我有一个静态表格 View ,其中有几个单元格,我想在初始表格 View 设置中调整其 alpha 值。在 cellForRowAtIndexPath 中进行这些调整不工作。调整后的每个单元格在屏幕上显示的 alpha 均为 1.0,尽管我在 cellForRowAtIndexPath 中将其 alpha 记录为 0。 .

由于我对调整单个部分的所有单元格感兴趣,因此我能够通过在viewWillAppear中包含类似的内容来获得所需的功能。 :

- (void)changeAlphaOfCells:(float)alpha
{
for (int i = 0; i < NUMBER_OF_ROWS_IN_SECTION; i++)
{
UITableViewCell *cell = [[self tableView] cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:SECTION_NUMBER]];
cell.alpha = alpha;
}
}

您需要逻辑来确定在 viewWillAppear 中调整哪些单元格的 Alpha ,并使用 cellForRowAtIndexPath. 检索它们不像 cellForRowAtIndexPath 中的单行调用那么优雅,但还不错。

关于ios - 静态 UITableView 出现禁用的不透明 alpha 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17366486/

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