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.
Related
I have the following Image Set defined in my Media.xcassets library...
I am loading this image to a button as follows...
public override void ViewDidLoad()
{
base.ViewDidLoad();
FSDirectButton.SetImage(UIImage.FromBundle("FSDirectButton"), UIControlState.Normal);
}
However, the button is not the correct size. How do I load an image to a button and then have the button resize to fit the image? I am not sure which image is being picked (1x, 2x, 3x).
Here is a recipe that I have used in the past that has helped greatly: https://developer.xamarin.com/recipes/ios/standard_controls/buttons/use_an_image_for_a_button/
a few things you may also want to consider trying:
1. Make sure constraints are set so that the button is always the right size
2. If all else fails try adding the images to your resource folder and accessing them as files instead as a temporary workaround.
3. also, you may want to try SetBackgroundImage(), instead of SetImage to see if it yields different results.
4. Try setting the image for all the control states of the button (highlighted, disabled, etc.)
5. try changing the content mode for the imageview inside the button. It may just be that the image is too large and doesn't scale to fit the alloted space. access this by using FSDirectButton.ImageView.ContentMode
To answer your question about which image size is selected (1x, 2x, etc.), I believe that is determined by the resolution of the IOS device that the image is being displayed on. that way if someone uses an iphone or an iPad the image will still look nice and clear without you having to write a lot more code to choose the best image for each device.
How do I load an image to a button and then have the button resize to
fit the image?
If you want your button auto resizing to fit its image. Please use Autolayout to layout your button.
Try to add the top constraint and left constraint to define the element's position in X and Y. Then the button will auto adjust its size depending on its content if we don't add the width and height constraint to the button.
I am not sure which image is being picked (1x, 2x, 3x).
After adding the images, the system will decide which image should be picked depending on which device the app run on. we just need to use the image name without the suffix. More details about which device picks which type of image you can refer to this
#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)
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!
Here is a view with a UIImageView in it. I will set different images to it determined by different situation. So what i do is to get the size of image to resize the view. Do we have a better way to determine the size of the UIImageView and not to resize its size?
I face this problem when i have a UITableViewCell in the middle of a UITableView. I show my tableview first without the image. Then after i got the image, i reload the cell to resize the image view. It seems it is not so good in visual effect.
In my ios project I'm using a uicollectionview and custom CollectionViewCells to load local images saved on the device (through ALAssets).
My problem occurs when the user scrolls down and then back up. It seems as though it takes long enough for ALAssets to load the image (I'm not using the thumbnail version) which gets it confused and sets the cell's wrong image. I know for sure that it's the wrong cell's image, as it has already been set in the past with the correct image.
How can I overcome this issue and synchronize the image loaded?
Cancel ALAssets operations connected to each cell inside this function:
- (void)prepareForReuse
in your custom cells class. That should prevent updating image on cell which were reused and which has different content.