Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/101.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/svn/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UITableView,UILabel文本颜色在选择行时不更改?_Ios_Objective C_Xcode_Ios7_Uilabel - Fatal编程技术网

Ios UITableView,UILabel文本颜色在选择行时不更改?

Ios UITableView,UILabel文本颜色在选择行时不更改?,ios,objective-c,xcode,ios7,uilabel,Ios,Objective C,Xcode,Ios7,Uilabel,我有UITableView,我在UITableView中有四个带有文本(白色)的标签,当我选择要在blackColor中更改标签textcolor的行时,你应该使用didSelectRowAtIndexPathtableView委托方法: - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // Change your text color here

我有
UITableView
,我在
UITableView
中有四个带有文本(白色)的标签,当我选择要在
blackColor
中更改标签
textcolor
的行时,你应该使用
didSelectRowAtIndexPath
tableView委托方法:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
      // Change your text color here.
}

单元格中,使用以下代码:

选择:

label.highlightedTextColor = [UIColor blackColor];
label.textColor = [UIColor whiteColor];
正常:

label.highlightedTextColor = [UIColor blackColor];
label.textColor = [UIColor whiteColor];

默认情况下,
ui标签的
textColor
blackColor
。您的标签的
textColor
如何更改为
whiteColor

无论如何,您可以这样更改标签的
textColor

label.textColor = [UIColor blackColor];

祝你一切顺利

没有你的代码,很难说你错在哪里?但我把我的逻辑放在这里

首先在
cellforrowatinexpath
中为每个
UILabel
提供标签,如

lbl1.tag = 101;
lbl2.tag = 102;
.
.
.
然后

- (void)tableView:(UITableView *)tv didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [self tableView:tv cellForRowAtIndexPath:indexPath];

    UILabel *label = (UILabel*)[cell viewWithTag:101]; // you can get label like
    [label setTextColor:RedColor]; // set as you want
    .
    .
    // write for each label

}
并将其设置为取消选择单元格时的颜色

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{
    UITableViewCell *cell = [self tableView:tv cellForRowAtIndexPath:indexPath];

    UILabel *label = (UILabel*)[cell viewWithTag:101]; // you can get label like
    [label setTextColor:RedColor]; // set color as it is
    .
    .
    .
    // write for each label
}

我只在最后一行尝试了更改。使用标记或indexPath获取所选单元格并对其进行更改。如果在tableview Selecting中不起作用,则需要在didSelectRowAtIndexPath方法中使用所选索引,和更改UILabel的文本颜色。我创建了UILabel及其文本颜色,然后将子视图添加到cell.contentview。现在我正在尝试更改didselectrow中的颜色,但它没有更改,选择任何行的最后一行中只显示颜色更改我只创建了一个uilabel,标记为indexpath.row,但不是working@RameshKumar-那就跟我来。是的,我想这个标签会起作用的,因为标签在手机内…@iPatel我试过了,但没有working@RameshKumar-然后把代码放在这里。或者您是否已将
[cell viewWithTag:101]
更改为
[cell viewWithTag:indexPath.row]