使用 sdwebimage 在 collectionView 中的 imageview 中上传图像

Upload image in imageview inside collectionView using sdwebimage

我必须使用 SDWebImage

imageView 中显示图像

这是我的代码:

NSString *string2 = [[dataArray objectAtIndex:indexPath.row ]valueForKey:@"logo"];

[imagev sd_setImageWithURL:[NSURL URLWithString:@"http://dev-demo.info.bh-in-15.webhostbox.net/dv/nationalblack/upload/post/"]
                  placeholderImage:[UIImage imageNamed:string2]
                         completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
                             imagev.image = image;
 }];

我没有在里面获取任何图像 ImageView

我从服务器获取的数据是

data array (
        {
        address = brisbane;
        amount = 0;
        "business_phone" = 9990688436;
        catid = 0;
        catname = "";
        city = delhi;
        contactperson = "Gautam Kumar";
        country = Australia;
        createdon = 1464935578;
        email = "gautam.kumar@eyeforweb.com";
        expirydays = 366;
        expirymail = 0;
        "fb_address" = "";
        id = 78;
        "inst_address" = "";
        isexpired = 0;
        isfeatured = 0;
        lat = "-33.7961";
        "link_address" = "";
        lng = "151.146";
        logo = "";
        longdesc = "xyz ";
        mobileno = "";
        officephone = "";
        ondedaysmail = 0;
        "package_name" = 0;
        paidamount1 = 0;
        paydate1 = 0;
        paystatus1 = 1;
        "prod_name" = 13;
        "pt_address" = "";
        sevendaysmail = 0;
        shortdesc = hello123;
        state = "New South Wales";
        status = 1;
        tags = "";
        "tb_address" = "";
        title = aayush;
        transcationid1 = "";
        "tw_address" = "";
        userid = 5;
        username = "Gautam Kumar";
        "var_name" = 56;
        "web_address" = "";
    },
        {
        address = "Address 1";
        amount = 0;
        "business_phone" = 9990688436;
        catid = 0;
        catname = "";
        city = ABD;
        contactperson = "Gautam Kumar";
        country = Australia;
        createdon = 1464158696;
        email = "gautam.kumar@eyeforweb.com";
        expirydays = 357;
        expirymail = 0;
        "fb_address" = "";
        id = 75;
        "inst_address" = "";
        isexpired = 0;
        isfeatured = 0;
        lat = "-37.488";
        "link_address" = "";
        lng = "144.592";
        logo = "appflowchart_4c1.gif";
        longdesc = "This is short Description.";
        mobileno = "";
        officephone = "";
        ondedaysmail = 0;
        "package_name" = 0;
        paidamount1 = 0;
        paydate1 = 0;
        paystatus1 = 1;
        "prod_name" = 3;
        "pt_address" = "";
        sevendaysmail = 0;
        shortdesc = "This is short Description.";
        state = Gisborne;
        status = 1;
        tags = "";
        "tb_address" = "";
        title = Business1;
        transcationid1 = "";
        "tw_address" = "";
        userid = 5;
        username = "Gautam Kumar";
        "var_name" = 0;
        "web_address" = "";
    },
        {
        address = "Paschim Vihar ,Delhi";
        amount = 0;
        "business_phone" = 9990688436;
        catid = 0;
        catname = "";
        city = "New Delhi";
        contactperson = "Gautam Kumar";
        country = Australia;
        createdon = 1464065014;
        email = "gautam.kumar@eyeforweb.com";
        expirydays = 356;
        expirymail = 0;
        "fb_address" = Facebook;
        id = 72;
        "inst_address" = Instagram;
        isexpired = 0;
        isfeatured = 0;
        lat = "-37.488";
        "link_address" = linked;
        lng = "144.592";
        logo = "Screenshot_(1)_61b.png";
        longdesc = sdfsdfdsf;
        mobileno = "";
        officephone = "";
        ondedaysmail = 0;
        "package_name" = 0;
        paidamount1 = 0;
        paydate1 = 0;
        paystatus1 = 1;
        "prod_name" = 3;
        "pt_address" = Pinsta;
        sevendaysmail = 0;
        shortdesc = fffsdf;
        state = Gisborne;
        status = 1;
        tags = "";
        "tb_address" = Tumbler;
        title = "First business";
        transcationid1 = "";
        "tw_address" = Twitter;
        userid = 5;
        username = "Gautam Kumar";
        "var_name" = 2;
        "web_address" = Website;
    },
        {
        address = Laxminagar;
        amount = 0;
        "business_phone" = 9990688436;
        catid = 0;
        catname = "";
        city = "New Delhi1";
        contactperson = "Gautam Kumar";
        country = Australia;
        createdon = 1463651418;
        email = "gautam.kumar@eyeforweb.com";
        expirydays = 7;
        expirymail = 0;
        "fb_address" = Facebook;
        id = 61;
        "inst_address" = Instagram;
        isexpired = 0;
        isfeatured = 0;
        lat = "28.6433";
        "link_address" = linked;
        lng = "77.0363";
        logo = "Screenshot_(1)_0ba.png";
        longdesc = asxasxasx;
        mobileno = "";
        officephone = "";
        ondedaysmail = 0;
        "package_name" = 0;
        paidamount1 = 0;
        paydate1 = 0;
        paystatus1 = 1;
        "prod_name" = 3;
        "pt_address" = Pinsta;
        sevendaysmail = 0;
        shortdesc = xasxasx;
        state = Victoria;
        status = 1;
        tags = "";
        "tb_address" = Tumbler;
        title = "Testing by Gautam";
        transcationid1 = 1111111111111;
        "tw_address" = Twitter;
        userid = 5;
        username = "Gautam Kumar";
        "var_name" = 2;
        "web_address" = Website;
    }
)

阿尤什·卡蒂亚尔,

从 iOS 8 开始,您不应该使用 http,您应该使用安全通道 https。如果你没有,请考虑将这些添加到你的 plist

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

您下载的所有图片 api 都使用了 http:// 我猜这可能是这里的问题

最后将加载图像的方式更改为

[imagev sd_setImageWithURL:[NSURL URLWithString: [NSString stringWithFormat:@"%@/%@",@"http://dev-demo.info.bh-in-15.webhostbox.net/dv/nationalblack/upload/post/", string2]]
                  placeholderImage:[UIImage imageNamed:@"Some_Placeholder_Image"]
                         completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
                             imagev.image = image;
 }];

就这样使用,

 [cell.myImageView sd_setImageWithURL:finalImageUrl];

finalImageUrl 是您最后的 url 下载图片。

无需使用带有完成处理程序的方法。它用于不同的任务。