Ios UITableViewCell未响应setNeedsLayout
我有一个分组格式的Ios UITableViewCell未响应setNeedsLayout,ios,objective-c,uitableview,uiview,Ios,Objective C,Uitableview,Uiview,我有一个分组格式的UITableView,其中有几个单元格。单元格中有一个UIView,我正在向其中添加另一个UIView。当我更新第一个UIView的框架时,它不会更改其位置或大小 ui视图如果单元格再次出现屏幕外和屏幕上,则会正确地重新对齐,因此实际的转换正在应用,只是重新渲染没有正确进行 这方面的代码就在myCellForRowatineXpath中: [cell.cellMoney setBackgroundColor:[UIColor clearColor]]; [cell.cell
UITableView
,其中有几个单元格。单元格中有一个UIView
,我正在向其中添加另一个UIView
。当我更新第一个UIView
的框架时,它不会更改其位置或大小
ui视图
如果单元格再次出现屏幕外和屏幕上,则会正确地重新对齐,因此实际的转换正在应用,只是重新渲染没有正确进行
这方面的代码就在myCellForRowatineXpath
中:
[cell.cellMoney setBackgroundColor:[UIColor clearColor]];
[cell.cellMoney.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
UIView *sellMoneySubView = [UIMoneyDisplay createViewWithAmount:item.min_sale_unit_price fontSize:17.0];
[cell.cellMoney setFrame:CGRectMake(cell.frame.size.width-sellMoneySubView.frame.size.width-20, 7, sellMoneySubView.frame.size.width, sellMoneySubView.frame.size.height)];
[cell.cellMoney addSubview:sellMoneySubView];
[cell setNeedsLayout];
我添加到第一个UIView
的子UIView
被正确添加和渲染,只是第一个的位置变得奇怪
哦,我还在故事板上使用自动布局
另外:我修复了部分问题,但标题仍然有效。我还有一个需要通过网络下载图像的单元格,但该单元格也不响应任何形式的布局调用
我修复了UIView
位置的问题,方法是删除中间视图并直接添加到单元格的contentView
[cell setNeedsLayout]
使用[需要单元格布局]
[cell.cellMoney setBackgroundColor:[UIColor clearColor]];
[cell.cellMoney.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
UIView *sellMoneySubView = [UIMoneyDisplay createViewWithAmount:item.min_sale_unit_price fontSize:17.0];
[cell.cellMoney setFrame:CGRectMake(cell.frame.size.width-sellMoneySubView.frame.size.width-20, 7, sellMoneySubView.frame.size.width, sellMoneySubView.frame.size.height)];
[cell.cellMoney addSubview:sellMoneySubView];
[cell layoutIfNeeded]; //use this
return cell;
这可能会对您有所帮助:)感谢您对其进行编辑。我完全忘记了将类名放在代码格式中。请阅读以下内容:我试过了,它不起作用<代码>设置需要显示也不起作用。