作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我创建自定义单元格并为某些单元格添加新的 subview :
static NSString *cellIdentifierCell = @"Cell";
FeedCell *cell = (FeedCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifierCell];
if (!cell)
{
cell = [[FeedCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifierCell]; //frame
}
//here add subView
if (wallPost.attachmentLinks[@"audio"])
{
NSLog(@"%ld",(long)indexPath.row);
[cell addAudio:wallPost.attachmentLinks[@"audio"] fromStartFrame:CGRectMake(10, 50 + collectionHeight + 5 + 90 + 5, 300, 20)];
} else {
for (UIView *v in cell.subviews) //// (1)
{
if (v.tag == 333)
{
[v removeFromSuperview];
}
}
}
这是我使用的单元格方法:
- (void)addAudio:(NSArray *)arrayAudio fromStartFrame:(CGRect)frame
{
for (NSDictionary *dic in arrayAudio)
{
UIView *audioView = [[UIView alloc]init];
audioView.frame = CGRectMake(10, frame.origin.y-100, 300, 20);
audioView.backgroundColor = [UIColor yellowColor];
audioView.tag = 333;
[self addSubview:audioView];
}
[self layoutSubviews];
}
问题是我在不能有 subview 的单元格中有 subview 。第 (1) 部分不运行。如何重置单元格或从中删除自定义 View ?
最佳答案
如果创建两个单元格 View 会更好。它不是使用标签删除 View 的最佳方法。在您的代码的其他部分,只需使用替代 View ,该 View 将看起来像空 View 。这可能是处理这种情况的替代方法。
关于ios - 如何重置 iOS 中的 uitableViewCell 内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23003674/
我是一名优秀的程序员,十分优秀!