[英]What subview are all the cell subviews located at? (In the custom cell class)
I have a custom UITableViewCell
with a class linked to it. 我有一个自定义的
UITableViewCell
,带有链接到它的类。
In awakeFromNib
, (of the custom cell class,) I made a for in
loop: 在(自定义单元格类的)
awakeFromNib
,我做了一个for in
循环:
for (id view in self.subview)
{
if (view isKindOfClass:[UITextField class]) {
UITextField *textField = (UITextField *)view;
[textField setBackgroundColor:[UIColor redColor]];
}
}
When I run it on the simulator, no textFields
background color changes. 当我在模拟器上运行它时,没有
textFields
背景颜色发生变化。
I'm pretty sure, that what I have wrong is: self.subview
. 我很确定,我做错的是:
self.subview
。 What should I put in place of that? 我该怎么代替呢?
Give a tag to your view in the cell that contain textfield let suppose tag = 0
for (UIView *view in [self viewWithTag:0].subviews)
{
if ([view isKindOfClass:[UITextField class]]) {
UITextField *textField = (UITextField *)view;
[textField setBackgroundColor:[UIColor redColor]];
}
}
Hope this help. 希望能有所帮助。
Get subviews from self.contentView - 从self.contentView获取子视图-
Try the following code 试试下面的代码
for (id view in self.contentView.subviews) {
if ([view isKindOfClass:[UITextField class]]) {
UITextField *textField = (UITextField *)view;
[textField setBackgroundColor:[UIColor redColor]];
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.