2

I'm trying to display 3 image views, along with some additional information in a UILabel, in a UITableView. Attached is an image of my Cell Prototype:

enter image description here

Currently, my issue is that the image content is running over to the following cell. As I test, I'm currently only loading the largest image of the 3 (I pull them from a server presorted from largest to smallest-- I'll also note that the images will be subject to various dimension constraints).

My issue is that, while its width is working correctly, its height runs over the metrics label and into the next cell.

I now know that in order for this to work, auto layout constraints have to be properly configured. However, I'm new to this and am having some trouble with it.

To start, I'll try and explain exactly what I'm looking to accomplish:

  1. The description label should span across the entire table cell.

    • To do this, I've pinned the leading, top & trailing spaces to the superview
  2. I would like the top right and top left image to both be positioned directly below the description label. To do this, I've:

    • Pinned the leading space of the top right image to the superview
    • Pinned the trailing space of the top left image to the superview
    • Pinned the top space of both images to the Description label
    • Pinned the horizontal spacing between these two images
  3. I would like the bottom right directly under the top right, to do this, I've:

    • Pinned the leading space of the bottom right image to the superview
    • Pinned the top space of the bottom right image to the top right image
  4. I'd like the metrics label to appear below the top left image, to do this, I've:

    • Pinned the top space of this label to the top left image
    • Pinned the bottom and and trailing edges of metrics to the super view
    • Pinned the leading space of metrics to the bottom right image.

I'm certain I'm doing something wrong here, should I not be pinning subviews to each other at any point?

Also, apologies for my presentation of this issue. Below is an image of the warnings I'm getting (for your reference, Image 1 is top right, Image 2 is top left, and Image 3 is bottom right) When I view the constraints of each of the image views, each side IS accounted for.

Any help would be appreciated! Thanks.

enter image description here

shaunvxc
  • 182
  • 4
  • 12
  • you need to **post an example** - I mean an image - of the problem you are having. this: "Currently, my issue is that the image content is running over to the following cell." is totally unclear dude. don't hesitate to post one or indeed many full examples showing your problem. – Fattie May 13 '15 at 01:23
  • Okay, I will edit my question now and add some screen shots. I was so vague initially! – shaunvxc May 13 '15 at 01:29
  • Just one very general point, Shaun. Note that truly completely dynamic cells and tables (or these days, collection views - nobody uses tables anymore) in large scrolling views, is, quite simply, the hardest thing in iOS and Android programming! Like, Facebook has trouble with it. for many subtle issues there are no answers. (like my challenge in the other comment, what do you do about an extremely thing image? who knows.) – Fattie May 13 '15 at 01:46
  • many generally tricky issues arise. general tricky issues .. http://stackoverflow.com/questions/20238559/ and don't even mention ultimately you will have to deal with the "skimming" and "lazy-loading" issues. http://stackoverflow.com/questions/25747696/ and of course there's the whole general issue of loading an "infinite" list. when you as a user casually "infinitely" scroll backwards on your facebook cat photos page, that's like "real engineering". you know? don't even mention editing, deleting items etc when dealing with such huge scrolls on the fly. – Fattie May 13 '15 at 01:48
  • I've updated my question, and tried to explain things more clearly. As far as edge cases (like thin images)-- any images that will be presented in this feed will be subject to certain constraints (i.e. minimum size). Let me know if you need any more info! – shaunvxc May 13 '15 at 02:18
  • "any images that will be presented in this feed will be subject to certain constraints" that's absolutely impossible, there are no such constrains in this univers" it's a truly fundamental aspect of programming! you'll have to deal with every image shape. (even if, that means at worst "discard images which are not appropriate.) – Fattie May 13 '15 at 08:22
  • Joe- the images that I pull from the feed, will be uploaded by users of a service I'm working on. The images that they upload will be subject to certain constraints-- ie, minimum sizes, etc. Still sound impossible to you? – shaunvxc May 13 '15 at 13:58
  • sure, it's impossible! :) so, here's a trivial example. I'm imagining there's some software that allows them to upload. and that software enforces certain sizes. ok - 100.000% of software has bugs, so you can't rely on that software enforcing the sizes. there'll come times when you get "bad" sizes. it's very basic - all software has to, in a word, check any incoming data or material. So, it's no harder than this: you'd look for ridiculous sizes, and discard those images (or perhaps bring up a placeholder image there). – Fattie May 14 '15 at 02:36

1 Answers1

1

try adding this code to your viewDidLoad:

override func viewDidLoad() {
    super.viewDidLoad()
    tableView.estimatedRowHeight = tableView.rowHeight
    tableView.rowHeight = UITableViewAutomaticDimension
}
Leszek
  • 71
  • 1
  • 7
  • 1
    Yes-- as specified in my question above, I've done both of these things. Still doesn't seem to be working for me. The only difference is I've set tableView.estimatedRowHeight = and not tableView.rowHieght-- would that fix the issue? – shaunvxc May 12 '15 at 19:57
  • tableView.estimatedRowHeight = tableView.rowHeight wil automaticly get the value from storyboard. Make sure Your constraints are set up correctly (to top and to bottom of Your prototype cell) – Leszek May 12 '15 at 20:08
  • will confirm this when I get home, but I don't think there are any auto-layout warnings, and in storyboard the constraint lines are all blue (I'm pretty sure of this, but will recheck it) – shaunvxc May 12 '15 at 20:10
  • So I've double checked my constraints and I'm pretty sure they are correct-- at least, no warnings are generated. How can I know for sure if I've set them up correctly? – shaunvxc May 13 '15 at 00:10
  • you make careful screenshots of everything and post them here :) – Fattie May 13 '15 at 01:24