ios - 如何根据图像大小设置高度单元格
<p><p>我从不同大小的 URL 获取图像。我已经根据图像高度设置了单元格高度。 </p>
<pre><code>] placeholderImage: success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
cell.imgshow.image = image;
imageStatus =@"Load";
if (image != nil) {
// ;
];
NSLog(@"%@",images);
withRowAnimation:UITableViewRowAnimationNone];
}
</code></pre>
<p>这是我用于图像加载和引用代码的代码。</p>
<pre><code>-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
UIImage *image = (UIImage *)[images objectForKey:
[NSString stringWithFormat:@"%li,%li",
(long)indexPath.row,(long)indexPath.section]];
if (image != nil)
{
return image.size.height+300;
}
else{
return 300.0;
}
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>希望对你有所帮助。</p>
<pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
...
placeholderImage:
success:^(UIImage *image, BOOL cached) {
// save height of an image to some cache
forKey:urlKey];
;
withRowAnimation:UITableViewRowAnimationFade];
;
}
failure:^(NSError *error) {... failure code here ...}];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
// try to get image height from your own heights cache
// if its is not there return default one
CGFloat height = [ floatValue];
...
return newHeight;
}
</code></pre>
<p>欲了解更多信息,请参阅以下链接。</p>
<p> <a href="https://github.com/jurezove/dynamic-uitableviewcells/tree/master" rel="noreferrer noopener nofollow">https://github.com/jurezove/dynamic-uitableviewcells/tree/master</a> </p></p>
<p style="font-size: 20px;">关于ios - 如何根据图像大小设置高度单元格,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/32443094/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/32443094/
</a>
</p>
页:
[1]