【问题标题】:IOS set element width constraint to 0 when in located inside UITableViewCellIOS 在位于 UITableViewCell 内时将元素宽度约束设置为 0
【发布时间】:2013-08-20 07:28:29
【问题描述】:

具有自动布局模式的 IOS 6。

我有带有自定义 UITableViewCell 的 UITableView。

它有两个 UILabel (Header 和 Status)

当项目状态为空时,我需要将状态约束宽度设置为零,以隐藏它。 我该怎么做?

我正在使用以下技术访问 UITableViewCell 内的标签。

UIView *status = (UIView*)[cell.contentView viewWithTag:10];
status.text=@"Sample text";

【问题讨论】:

    标签: iphone ios6 uitableview constraints autolayout


    【解决方案1】:

    我找到了访问 UITableViewCell 中元素约束的解决方案

    1-st 我是 UITableViewCell 的子类

    然后添加IBOutlet

    @interface UICustomTableViewCell : UITableViewCell
    {
    IBOutlet NSLayoutConstraint* statusWidth;
    }
    
    @property(nonatomic,retain)NSLayoutConstraint *statusWidth;
    
    @end
    

    然后将其分配给故事板上的单元原型,并使用 IBOutlet 链接状态宽度约束

    现在当我出列单元格时

    UICustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
    

    我可以将状态约束设置为零。

    cell.statusWidth = 0;
    

    【讨论】:

      猜你喜欢
      • 2020-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-14
      • 1970-01-01
      • 1970-01-01
      • 2014-10-16
      • 2016-06-11
      相关资源
      最近更新 更多