使用方法网上很多不赘诉,只说注意事项,不做会崩溃
1、 storyboard中动态Cell所在的section中必须预留一个Cell,可以是任意一个Cell;
2、 - (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath;方法必须重写;
- (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath{
if(1 == indexPath.section){
return [super tableView:tableView indentationLevelForRowAtIndexPath: [NSIndexPath indexPathForRow:0 inSection:1]];
}
return [super tableView:tableView indentationLevelForRowAtIndexPath:indexPath];
}
3、 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;方法必须重写;
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if(1 == indexPath.section){
return 100.0;
}
return [super tableView:tableView heightForRowAtIndexPath:indexPath];
}
日常开发使用心得整理,如有纰漏,欢迎指正!!!
本文分享了在Storyboard中实现动态Cell的三个关键步骤:预留Cell、重写indentationLevel及heightForRowAtIndexPath方法。确保section中至少有一个预留Cell,并正确设置Cell的缩进级别和高度,以避免布局崩溃。
和动态cell(dynamic cell)混合使用注意事项&spm=1001.2101.3001.5002&articleId=101296587&d=1&t=3&u=54784851b5df404cb99734884584f770)
111

被折叠的 条评论
为什么被折叠?



