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
IOS中的自定义表视图单元格?_Ios_Uitableview - Fatal编程技术网

IOS中的自定义表视图单元格?

IOS中的自定义表视图单元格?,ios,uitableview,Ios,Uitableview,我有自定义的UITableViewCell。 UITableViewCell有一个UILabel和一个UIButton。我想当点击按钮,然后标签的文字改变颜色为“红色”。 我不处理???在自定义表格视图单元格中为按钮设置内部润色事件,如下所示 [self.button addTarget:self action:@selector(clicked:) forControlEvents:UIControlEventTouchUpInside]; 在同一个类中添加以下方法 -(IBAction)

我有自定义的
UITableViewCell
UITableViewCell
有一个
UILabel
和一个
UIButton
。我想当点击按钮,然后标签的文字改变颜色为“红色”。
我不处理???

在自定义表格视图单元格中为按钮设置内部润色事件,如下所示

[self.button addTarget:self action:@selector(clicked:) forControlEvents:UIControlEventTouchUpInside];
在同一个类中添加以下方法

-(IBAction) clicked:(id)sender {
    [self.label setTextColor:[UIColor redColor]];
}

您可以做的一件事是维护一个数组,该数组的每个元素表示相应的行号。
使用0初始化该数组意味着所有标签都将使用黑色文本
现在为行方法将每个按钮的索引设置为单元格中的index path.row。
现在单击按钮时,将index button.tag处数组中的值设置为1,将其他值设置为0,然后重新加载tableview。
现在为行,在单元格中检查索引indexath.row==1处数组中的项是否为红色,然后将uilabel的颜色设置为红色或黑色

当您单击cell1中的按钮->更改cell1的颜色,单击cell2中的按钮->更改cell2的颜色时,显示您想要的代码?我理解,但当我单击cell1,然后单击cell3上的文本更改为“红色”。文本单元格1不改变颜色。我想点击第二个文本返回“黑色”