Objective c 静态UITableView中的自定义UITableViewCell
我已经定义了一个自定义的Objective c 静态UITableView中的自定义UITableViewCell,objective-c,ios,uitableview,Objective C,Ios,Uitableview,我已经定义了一个自定义的UITableViewCell,我正在静态UITableView中使用它。我想访问我定义的变量(myTableViewImageCell,等等),但从tableView:willDisplayCell执行此操作似乎意味着“重新定义单元格类型” 以下是我正在做的: - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIn
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)];
}
如果所有单元格都是同一个自定义类,则只需更改方法的定义即可,并去掉第一行(无论如何这是错误的):
但是,请注意,如果您对所有的单元格执行相同的操作(如此处所示),您应该在
cellForRowAtIndexPath:
中执行此操作,而不是在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]];
}
谢谢,我(错误地)认为我不应该在静态表视图中使用CellForRowatineXpath。事实上,我没有想过。你应该能够添加
ANMyTableViewCell*cell=[super tableView:tableView CellForRowatineXpath:indexPath]
作为cellforrowatinedexpath
的第一行,并在完成配置后返回单元格;
。@ang这不是真的吗?将cellforrowatinedexpath
方法添加到我的表处理程序中会覆盖静态单元格并停止渲染。好奇-你说的“静态UITableView”是什么意思?只有静态单元格的UITableView。好的,“静态单元格”是什么?对我来说,细胞就是细胞。我想知道,在你看来,静态单元格和非静态单元格之间有什么区别,以及它们是如何和为什么被区别对待的。@rmaddy:这是一个UITableView
,在故事板中将内容设置为静态单元格。UITableViewController
自动显示故事板中配置的所有单元格。@rmaddy:请参阅并查看“从故事板加载表格视图单元格”和“静态行内容的技术”部分。他们很好
- (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]];
}