Eddie K
Eddie K

Reputation: 513

Autolayout with fixed-dimension UIImageView when image is nil?

I have a UITableViewCell with some labels and a UIImageView that has a fixed dimension of 70x70. However, I can't seem to get rid of it when the image is nil -- a black square still appears. I have tried changing the content hugging priorities as well as changing the width to <= 70, but the empty imageview never fully disappears. Here are the imageview's current constraints:

enter image description here

enter image description here

Upvotes: 2

Views: 1174

Answers (2)

Eddie K
Eddie K

Reputation: 513

I ended up solving it by dragging the width constraint of the UIImageView into my code and then setting its constant to 0 if the image was nil as I was configuring my cell.

Upvotes: 5

SUNIL JOSHI
SUNIL JOSHI

Reputation: 190

you can do one thing with UIImageView when no image is there you can hide it simply. that can be implement at cell for row at index.

  -(UITableViewCell *)tableView:(UITableView *)tableView
                     cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString *CellIdentifier = @"SimpleTableCell";

            SimpleTableCell *cell = (SimpleTableCell *)[tableView
               dequeueReusableCellWithIdentifier:CellIdentifier];

            [cell.imageviewersetHidden:true];

    }

or you can hide it from xib and at the time of table view cell binding you can make it visible if image available to bind. i think this may help you.

Upvotes: 0

Related Questions