ios – 更新单元子视图的约束

ios – 更新单元子视图的约束,第1张

概述我有一个自定义单元&我正在尝试更新子视图约束,如下所示: CustomeCell.m -(void)layoutSubviews{ [super layoutSubviews]; _con_view_width.constant = _lbl_property.frame.size.width; if(!_btn_imageCount.isHidden) _c 我有一个自定义单元&我正在尝试更新子视图的约束,如下所示:

CustomeCell.m

-(voID)layoutSubvIEws{    [super layoutSubvIEws];    _con_vIEw_wIDth.constant = _lbl_property.frame.size.wIDth;    if(!_btn_imageCount.isHIDden)    _con_vIEw_wIDth.constant = _lbl_property.frame.size.wIDth + _btn_imageCount.frame.size.wIDth;    NSLog(@"%@",NsstringFromCGRect(_vIEw_lbl_btn.frame));    [_vIEw_lbl_btn updateConstraintsIfNeeded];    NSLog(@"%@",NsstringFromCGRect(_vIEw_lbl_btn.frame));}

问题
只有在滚动时重新加载行时,约束才起作用

解决方法 而不是updateConstraintsIfNeeded尝试layoutIfNeeded.我认为它会工作,你的代码应该是这样的.

-(voID)layoutSubvIEws{    [super layoutSubvIEws];    _con_vIEw_wIDth.constant = _lbl_property.frame.size.wIDth;    if(!_btn_imageCount.isHIDden)    _con_vIEw_wIDth.constant = _lbl_property.frame.size.wIDth + _btn_imageCount.frame.size.wIDth;    NSLog(@"%@",NsstringFromCGRect(_vIEw_lbl_btn.frame));    [_vIEw_lbl_btn layoutIfNeeded];    NSLog(@"%@",NsstringFromCGRect(_vIEw_lbl_btn.frame));}

编辑:如果您在自定义单元格类中执行此 *** 作,则需要在索引路径的行中为单元格添加一行.

- (UItableVIEwCell *)tableVIEw:(UItableVIEw *)tableVIEw cellForRowAtIndexPath:(NSIndexPath *)indexPath{    UItableVIEwCell *cell = [tableVIEw dequeueReusableCellWithIDentifIEr:@"Cell" forIndexPath:indexPath];    //[cell layoutIfNeeded];    [cell layoutSubvIEws];    return cell;}
总结

以上是内存溢出为你收集整理的ios – 更新单元子视图的约束全部内容,希望文章能够帮你解决ios – 更新单元子视图的约束所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1075189.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存