图像未在uiimageView中正确加载

时间:2016-05-27 10:57:23

标签: ios iphone uiimageview

请检查UIImageView中未正确加载的附加imageImage。

enter image description here

 profileCell.currentMsgView.userPicImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",object.mediaPath]] placeholderImage:[UIImage imageNamed:@"defaultImage"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { }]; 

2 个答案:

答案 0 :(得分:0)

尝试设置内容模式,例如

    profileCell.currentMsgView.userPicImageView.contentMode = UIViewContentModeScaleAspectFit;

并确保您已设置适当的约束。如果您有单元格大小的imageview,那么您的约束应该是:top,leading,trailing,bottom

这可以解决问题。

答案 1 :(得分:0)

尝试使用这个简单的演示应用程序进行学习: -

ViewController.h代码在这里: -

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
@property (strong, nonatomic) IBOutlet UIImageView *imageOutput;
- (IBAction)btnOutput:(id)sender;

@end

ViewController.m代码在这里: -

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)btnOutput:(id)sender {
    NSString *picUrl = @"http://cdn.wonderfulengineering.com/wp-content/uploads/2016/01/nature-wallpapers-9.jpg";
    NSURL *theUrl = [NSURL URLWithString:picUrl];
    NSData *imageData = [[NSData alloc]initWithContentsOfURL:theUrl];
    _imageOutput.image = [UIImage imageWithData:imageData];
}
@end

使用以下内容替换info.plist的整个代码,因为没有它,您将无法访问&#34; http site&#34;因为苹果会出于安全原因阻止http网站(右键点击info.plist并打开源代码): -

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSAppTransportSecurity</key>
<dict>
  <!--Include to allow all connections (DANGER)-->
  <key>NSAllowsArbitraryLoads</key>
      <true/>
</dict>
    <key>CFBundleDevelopmentRegion</key>
    <string>en</string>
    <key>CFBundleExecutable</key>
    <string>$(EXECUTABLE_NAME)</string>
    <key>CFBundleIdentifier</key>
    <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleName</key>
    <string>$(PRODUCT_NAME)</string>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <key>CFBundleShortVersionString</key>
    <string>1.0</string>
    <key>CFBundleSignature</key>
    <string>????</string>
    <key>CFBundleVersion</key>
    <string>1</string>
    <key>LSRequiresIPhoneOS</key>
    <true/>
    <key>UILaunchStoryboardName</key>
    <string>LaunchScreen</string>
    <key>UIMainStoryboardFile</key>
    <string>Main</string>
    <key>UIRequiredDeviceCapabilities</key>
    <array>
        <string>armv7</string>
    </array>
    <key>UISupportedInterfaceOrientations</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
    </array>
</dict>
</plist>