【发布时间】: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