【问题标题】:Cell text colour单元格文字颜色
【发布时间】:2014-10-12 06:59:06
【问题描述】:

我在使用

设置文本颜色这样简单的事情时遇到了问题
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier =@"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        cell.textLabel.textColor=[UIColor whiteColor];
        cell.detailTextLabel.textColor=[UIColor lightTextColor];
        cell.backgroundColor=[UIColor clearColor];

    }
    NSArray *array=[[NSArray alloc]initWithArray:messagingArrayToBeDisplayedInTableWhenCalloutTapped[indexPath.row]];

    cell.textLabel.textColor=[UIColor whiteColor];
    cell.detailTextLabel.textColor=[UIColor lightTextColor];
    cell.backgroundColor=[UIColor clearColor];
    cell.textLabel.text=[array objectAtIndex:0];
    cell.detailTextLabel.text=[array objectAtIndex:1];


    return cell;
}

背景颜色有效,但将文本颜色设置为 whiteColor 无效,因此标题和副标题均为默认灰色。我曾尝试在原型单元格中更改颜色,但这也不起作用。有人可以提出解决方案吗?在此先感谢:)

【问题讨论】:

  • 您在使用情节提要吗?如果是这样,您也可以在那里进行更改。
  • 可以删除6行代码,因为cell从不为零。
  • 我在属性检查器中更改了标签颜色,但没有任何反应
  • 我试过你的代码,它工作正常。当然我必须编一些文字,因为我没有你的数组。我还必须将 clearColor 更改为 blackColor 因为否则文本在白色背景上是白色的,我看不到它! :) 无论如何,由于我无法重现该问题,这证明您没有显示的 other 代码导致了它。因此,您没有提供足够的信息来重现。

标签: ios objective-c uitableview


【解决方案1】:

dequeueReusableCellWithIdentifier:forIndexPath: 总是返回一个有效的单元格,因此单元格永远不会为零,并且该代码永远不会执行。

所以去掉那个条件,看看它是否有效。

【讨论】:

    猜你喜欢
    • 2016-05-27
    • 1970-01-01
    • 2011-11-10
    • 2013-11-14
    • 2012-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多