简体   繁体   English

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

[英]Custom table view cell in IOS?

I have custom UITableViewCell .我有自定义UITableViewCell UITableViewCell have one UILabel and one UIButton . UITableViewCell有一个UILabel和一个UIButton I want when click button then text of label change color to "redColor".我希望当单击按钮时,标签文本将颜色更改为“redColor”。 I don't process???我不处理???

Inside your custom table view cell set touch up inside event for the button like this在您的自定义表格视图单元格中为这样的按钮设置 touch up inside event

[self.button addTarget:self action:@selector(clicked:) forControlEvents:UIControlEventTouchUpInside];

In the same class add the following method在同一个类中添加以下方法

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

one thing you can do is maintain an array whose each element represents the corresponding row number.您可以做的一件事是维护一个数组,其每个元素代表相应的行号。
Initialize the array with 0 means all the label will have text color black.用 0 初始化数组意味着所有标签的文本颜色为黑色。
Now set the index of each button equal to index path.row in cell for row method .现在将每个按钮的索引设置为 row method 单元格中的 index path.row 。
Now when the button is clicked set the value in array at index button.tag to 1 and others to 0 and reload tableview.现在,当单击按钮时,将索引 button.tag 处的数组中的值设置为 1,将其他值设置为 0 并重新加载 tableview。
Now in cell for row check if items in the array at index indexpath.row ==1 then set the color of uilabel to red else black.现在在行的单元格中检查索引 indexpath.row ==1 处的数组中的项目,然后将 uilabel 的颜色设置为红色,否则为黑色。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM