如果没有要加载的图像,如何更改表视图的大小
How to change size of a tableview if there is no image to load
我正在用一个 TableView 和一个 ImageView 做一个视图。我想从 URL 加载图像并根据需要更改 ImageView 组件的大小。但另一方面,如果 URL 中没有任何图像,我想隐藏 ImageView 组件并使 TableView 组件填满整个屏幕。
这是一个例子:
我该怎么做?
编辑:
毕竟我的代码就是这样,但是图像没有加载到 UIImageView :S
NSURL *imageURL = [NSURL URLWithString:[[bannerArray objectAtIndex:0] cvp_html]];
[SDWebImageDownloader.sharedDownloader downloadImageWithURL:imageURL
options:0
progress:^(NSUInteger receivedSize, long long expectedSize)
{
// progression tracking code
}
completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished)
{
if (image && finished)
{
NSLog(@"IMG DOWNLOAD COMPLETED");
dispatch_async(dispatch_get_main_queue(), ^(){
iv_banner = [[UIImageView alloc] initWithImage: image];
NSData *imgData = UIImageJPEGRepresentation(image, 0);
int heightOfTheTopButtons = 50;
if([imgData length] > 0) {
CGRect newFrame = CGRectMake(0, (heightOfTheTopButtons), self.view.frame.size.width, (self.view.frame.size.height-(heightOfTheTopButtons)) );
tableview.frame = newFrame;
}
});
}
}];
谢谢。
您可以检查图像数据是否大于 0。
UIImage * image = imageFromUrl;
NSData *imgData = UIImageJPEGRepresentation(img, 0);
if([imgData length] > 0) {
CGRect newFrame = CGRectMake(0, (heightOfTheTopButtons), self.view.frame.size.width, (self.view.frame.size.height-(heightOfTheTopButtons));
tableView.frame = newFrame;
}
我正在用一个 TableView 和一个 ImageView 做一个视图。我想从 URL 加载图像并根据需要更改 ImageView 组件的大小。但另一方面,如果 URL 中没有任何图像,我想隐藏 ImageView 组件并使 TableView 组件填满整个屏幕。
这是一个例子:
我该怎么做?
编辑:
毕竟我的代码就是这样,但是图像没有加载到 UIImageView :S
NSURL *imageURL = [NSURL URLWithString:[[bannerArray objectAtIndex:0] cvp_html]];
[SDWebImageDownloader.sharedDownloader downloadImageWithURL:imageURL
options:0
progress:^(NSUInteger receivedSize, long long expectedSize)
{
// progression tracking code
}
completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished)
{
if (image && finished)
{
NSLog(@"IMG DOWNLOAD COMPLETED");
dispatch_async(dispatch_get_main_queue(), ^(){
iv_banner = [[UIImageView alloc] initWithImage: image];
NSData *imgData = UIImageJPEGRepresentation(image, 0);
int heightOfTheTopButtons = 50;
if([imgData length] > 0) {
CGRect newFrame = CGRectMake(0, (heightOfTheTopButtons), self.view.frame.size.width, (self.view.frame.size.height-(heightOfTheTopButtons)) );
tableview.frame = newFrame;
}
});
}
}];
谢谢。
您可以检查图像数据是否大于 0。
UIImage * image = imageFromUrl;
NSData *imgData = UIImageJPEGRepresentation(img, 0);
if([imgData length] > 0) {
CGRect newFrame = CGRectMake(0, (heightOfTheTopButtons), self.view.frame.size.width, (self.view.frame.size.height-(heightOfTheTopButtons));
tableView.frame = newFrame;
}