Search code examples
iphoneios6uitableviewconstraintsautolayout

IOS set element width constraint to 0 when in located inside UITableViewCell


IOS 6 with auto layout mode.

I have UITableView with Custom UITableViewCell.

It has two UILabels (Header and Status)

When item status is empty i am need to set Status constraints width to zero, to hide it. How i can do this?

I am access labels inside UITableViewCell with following technique.

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

Solution

  • I found a solution to access elements constraints inside UITableViewCell

    1-st i am subclass UITableViewCell

    Then add IBOutlet

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

    Then assign it to my cell prototype on the storyboard and link status width constraint with IBOutlet

    Now when i dequeue cell

    UICustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
    

    i am able to set status constraint to zero.

    cell.statusWidth = 0;