繁体   English   中英

静态 UITableView 中的自定义 UITableViewCell

[英]Custom UITableViewCell in static UITableView

我已经定义了一个自定义UITableViewCell ,我在我的静态UITableView 我想访问我定义的变量( myTableViewImageCell等),但这样做tableView:willDisplayCell似乎是说一起的“细胞类型的重新定义线的东西。

这是我在做什么:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];

    [cell.myTableViewLabel setShadowColor:[UIColor whiteColor]];
    [cell.myTableViewLabel setShadowOffset:CGSizeMake(0.0f, 1.0f)];   


}

如果您的所有单元格都是同一个自定义类,您只需更改方法的定义以表明这一点并删除您的第一行(无论如何这是错误的):

- (void)tableView:(UITableView *)tableView willDisplayCell:(ANMyTableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];

    [cell.myTableViewLabel setShadowColor:[UIColor whiteColor]];
    [cell.myTableViewLabel setShadowOffset:CGSizeMake(0.0f, 1.0f)];
    [cell.myTableViewLabel setTextColor:[UIColor hex666Color]];      
}

但是请注意,如果您对所有单元格执行相同的操作(如您在此处显示的那样),您应该在cellForRowAtIndexPath:而不是willDisplayCell:执行此willDisplayCell: 这样,代码仅在创建单元格时运行一次,而不是每次显示时运行。

仅供参考,问题是无关的;细胞; 你在第二行的末尾。 将其更改为

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    ANMyTableViewCell *cell = (ANMyTableViewCell*)[tableView cellForRowAtIndexPath:indexPath];
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];

    [cell.myTableViewLabel setShadowColor:[UIColor whiteColor]];
    [cell.myTableViewLabel setShadowOffset:CGSizeMake(0.0f, 1.0f)];
    [cell.myTableViewLabel setTextColor:[UIColor hex666Color]];      
}

暂无
暂无

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

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