The width of images in UITableViewCell changes to the click - ios

#nathan this is my entire controller.
My problem is that when I click a tableview cell, the image size is changed and becomes too long.
I can not figure out how to fix the size, I tried everything.
To do URL parsing, I used NSXMLParser, while I used SDWebImage to load images into cells.
When I press an element its size changes.
Like this:
How to fix?

That seems like a content mode issue. Set the imageView's contentMode to aspectFit/aspectFill (depends on what you want to achieve)

Related

Update UITableViewCell height after asynchronously loading content

I'm using a framework to asynchronously load images (Pinterest's PINRemoteImage) in combination with a UITableView. On one of my UITableViewCells I have such an image and I first initialize it with a placeholder and it's then later replaced with the real image. I don't know the real image's dimensions at time of loading and therefore the placeholder's dimensions and the ones of the real image may be different.
Using KVO, I watch the UIImageView's image property and when it's re-set to the real image, I adjust the the view's height constraint to the appropriate size. This directly shows when I first see the image. It has the appropriate size.
The cell's contentView however, does not update it's height to fit around the image (and the other views) properly until the cell get's dequeued a second time. Only then is has the cell the appropriate height.
I assume that I have to tell the table or the cell itself that it needs to update the layout manually. But between all the layout… functions I'm not quite sure which to use where right now.
So, where's the best way to make the cell update it's height to the updated image height? Other answers to similar questions on SO suggest to reload the cell, but that seems a bit too much to me. And I'd have to build a callback from the cell (where the image lives) to the table itself which could then trigger the reload.
Thanks!

Not resizing downloaded images correctly

I have added a table view, and I am display image in the cells. I have also added this code:
So that the cells resize depending on the image.
When I launch my app though, I get this :
[![enter image description here][1]]
And the images do not load untill I start scrolling...If I scroll down half the page then go back to the top, I get this: Which is correct
[![enter image description here][2]][2]
Any ideas? I have researched on google and tried the odd solution for the older versions of Xcode, But nothing seems to work!
If the image is already downloaded and resident in your cache when you pass the post to the cell them the image view will have an image and therefore an intrinsic content size. This all allows the table view to calculate the required layout.
If the image needs to be downloaded then the image view won't have an image and will size to zero because there is no intrinsic content size other than that.
If your images are all the same size then you can supply a placeholder image while waiting for the download and the cell will size appropriately.
Note also that you aren't updating the cell when the image has downloaded. When you do this you do need to check that the cell hasn't been reused (or you'll be showing the wrong image). If you don't have a placeholder or can't guarantee the image size then you will also need to ask the table view to update.
Maybe your post.downloadImage() and post.fetchLikes() should callback, and in callback, should reload cell in mainThread. hope it help.

iOS 9 UIImageView scaling is erratic

I have a UICollectionView in my app. Each cell is about a third the width of the screen (in portrait orientation) and is square. Inside each cell is a UIImageView whose mode is set to "Scale To Fill" (in IB) and has constraints on each edge that force it to fill the cell.
On iOS 7 and 8, images would consistently perfectly fill each cell.
On iOS 9, scaling varies each time the view appears, and sometimes changes when the cell is clicked:
images sometimes are small, and sit in the upper left hand corner
images sometimes scale to fill as they should.
images sometimes scale slightly larger than the cell, and change size when the cell is selected.
images sometimes disappear completely when a cell is selected.
If it somehow matters, the image gets set in the cellForItemAtIndexPath method of the collection view like this:
cell.artImageView.image = artImage;
Where "artImage" is a UIImage. (Obj-C).
UIImageViews are pretty simple and straightforward. Did Apple "improve" them with some new property I need to set? Really stuck here.
Update: Tried to reproduce this in a new project and couldn't. Some kind of weird leftover IB juju. But totally replacing the collection view controller, cell and image view in IB did not fix the problem.
It turns out there was an extra view that wasn't "installed" for the size class.
I had this:
And changed it to this:
And now everything looks right!

iOS UIImageView beneath UITableView doesn't display correctly

I'm building a UITableView via the StoryBoard in XCode 6.3.1 for iPhone 6 app.
On this TableView, I want all of my cells, then beneath that, a UIImageView. I tested it for a small placeholder image, and it worked great. All of my cells display properly, and the image shows up beneath them.
The problem comes when I use my actual image (it's the size of the full screen). I want it to go directly below the Tableview, and have the bottom be viewable when the user scrolls down.
I tried messing with the view's attributes, and everything kept giving me some sort of issue. The default view mode of "Scale to Fill" makes the image look extremely distorted. Changing it to Aspect Fill makes the Image look perfect, but it makes all of the cells disappear when I run it (though not in the Storyboard for some reason)
Is there any way I can get the cells to display correctly, then place the undistorted image beneath it?

imageView in UITableView cell violates setClipsToBounds on touchdown event

I have a UITableView whose cells have an image from a URL placed in its imageView.
The image isn't square (is landscape), however it initially loads as a square in the manner in which contentMode is scaleAspectFill and setClipsToBounds is YES. So far so good.
However, when I touch down on the cell, the image "widens", that is, it retains the scaleAspect part, but now bleeds out to the right as if setClipsToBounds is NO.
The same behavior occurs if the row/cell goes out of view and comes back in recycled, in which case I have the image obtained from an in-memory cache rather than from the URL.
I've tried explicitly setting both contentMode and setClipsToBounds for the cell.imageView, but it seems to have no effect. Any advise? Thanks.
Before touchdown:
After touchdown (or recycle from cache):
imageView cell property (same as other textLabel and detailTextLabel) changes its frame in layoutSubviews accordingly to image size. So you can reimplement layoutSubviews to have fixed frame rect. BTW, try TableKit library.
Heres a link to the correct answer if anyone is still looking for a solution: UIImageView in UITableViewCell changes size on touchDown
Its because you named it imageView, name it something like image_View and the problem is solved!

Resources