相关疑难解决方法(0)

UITableViewCell和userInteractionEnabled的奇怪iOS错误

我刚刚注意到iOS上的UITableViewCell类和userInteractionEnabled属性有些奇怪.

看来如果将文本分配给单元格标签之前将userInteractionEnabled设置为NO ,则文本将显示为灰色.但是,在设置文本后将 userInteractionEnabled设置为NO会将文本颜色保留为黑色(请参阅下面的示例代码片段).

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (!cell)
       cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];

    // swap these two lines around, and the text color does not change to grey!
    cell.userInteractionEnabled = (indexPath.row % 2) == 0;
    cell.textLabel.text = @"Hello";

    return cell;
}
Run Code Online (Sandbox Code Playgroud)

这真的很烦人,因为这意味着在重用单元格的情况下,我最终会遇到不同的行为.上面的示例演示了这一点 - 表格的第一页显示了带有灰色/黑色文本的备用行.向下滚动以便细胞重复使用,您可以看到出现问题.

我只是想知道我做错了什么,或者这是一个iOS错误?我在iPad 3上看到了iOS 5.1下的问题.任何见解都非常感谢!

uitableview ios

9
推荐指数
1
解决办法
1785
查看次数

UITableViewCell textColor不会随userInteractionEnabled = NO而改变

我试图简单地改变我UILabel使用textColor属性的颜色,当禁用userInteraction时它将无法工作,这没有任何意义,文档中没有提到任何内容.但是,如果我删除该行颜色确实发生了变化,那就是正在发生的事情,但我不想要用户交互.

UITableViewCellStyleValue1
Run Code Online (Sandbox Code Playgroud)

单元格样式,单元格左侧带有标签,左对齐和黑色文本 ; 在右侧是一个标签,蓝色文字较小,右对齐."设置"应用程序使用此样式的单元格.适用于iOS 3.0及更高版本.

两个标签都是灰色,并且它们不会改变颜色.这是我的代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
    }

    //If I remove this line the color changes
    cell.userInteractionEnabled = NO;

    UIColor *blackColor = [UIColor blackColor];

    UILabel *mainLabel = cell.textLabel;
    UILabel *detailTextLabel = cell.detailTextLabel;
    mainLabel.backgroundColor = blackColor;
    detailTextLabel.backgroundColor = blackColor;

    //Trying to change color …
Run Code Online (Sandbox Code Playgroud)

iphone uitableview uilabel uicolor

4
推荐指数
1
解决办法
2523
查看次数

viewWillAppear期间的静态UITableViewCell更改未反映在显示中

我使用UITableViewCell情节提要中配置的一些static 来显示一些设置信息。

如果将其他设置之一关闭,则应禁用其他一些单元。

为了使单元格进入适当的状态,在此期间,viewWillAppear我从NSUserDefaults中读取了设置,然后相应地更改了单元格。

- (void) viewWillAppear:(BOOL)animated
    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"OtherCellEnabled"]) {
            [self otherCell].alpha = 1.0;
            [self otherCell].userInteractionEnabled = YES;
        }
        else {
            NSLog(@"Changing alpha to 0.3");
            [self otherCell].alpha = 0.3;
            [self otherCell].userInteractionEnabled = NO;
        }
Run Code Online (Sandbox Code Playgroud)

问题是,当我实际运行该程序时,即使它在日志中说Alpha已更改,但Alpha实际上并没有更改。的userInteractionEnabled似乎确实棒,但是阿尔法在1.0离开。

这不是单元重用的问题,也不是单元没有及时实例化的问题,因为可以更改其他设置。

将其从cell.alpha更改为cell.contentView.alpha是可行的,但这是不同的设置。

似乎所有设置都“粘住了”,但alpha设置已被覆盖。

objective-c uitableview ios

4
推荐指数
1
解决办法
2187
查看次数

标签 统计

uitableview ×3

ios ×2

iphone ×1

objective-c ×1

uicolor ×1

uilabel ×1