zoukankan      html  css  js  c++  java
  • 图片加载

    #import <UIKit/UIKit.h>

    @interface ViewController : UIViewController<NSURLConnectionDataDelegate>
    @property (strong, nonatomic) IBOutlet UIImageView *imageview;
    @property(nonatomic,strong)NSMutableData *recedate;
    - (IBAction)Done:(id)sender;

    - (IBAction)ShouCang:(id)sender;

    @end

    #import "ViewController.h"

    @interface ViewController ()

    @end





    @implementation ViewController

    - (void)viewDidLoad {
        _recedate =[[NSMutableData alloc]init];
        
        [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)Done:(id)sender
    {
        NSString *urlAsString=@"http://gaitaobao1.alicdn.com/tfscom/TB10NzeHXXXXXcFXVXXXXXXXXXX.jpg_180x180xz.jpg";
    //    NSURL *url=[NSURL URLWithString:urlAsString];
    //    NSURLRequest *urlRequest=[NSURLRequest requestWithURL:url];
    //   不可变
    //    [NSURLConnection connectionWithRequest:urlRequest delegate:self];
        
        
        NSURL *url=[NSURL URLWithString:urlAsString];
        NSMutableURLRequest *urlRequest=[NSMutableURLRequest requestWithURL:url];
       //可变
        [NSURLConnection connectionWithRequest:urlRequest delegate:self];
        
    }
    - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
    {
       [_recedate appendData:data];
        NSLog(@"走近");
    }
    - (void)connectionDidFinishLoading:(NSURLConnection *)connection
    {
        UIImage *image=[UIImage imageWithData:_recedate];
        self.imageview.image=image;
    }
    - (IBAction)ShouCang:(id)sender {
    }
    @end
    第二部分
    #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)Done:(id)sender {
        
        UIImage *image=nil;
        NSString *urlAsString=@"http://gaitaobao1.alicdn.com/tfscom/TB10NzeHXXXXXcFXVXXXXXXXXXX.jpg_180x180xz.jpg";
        NSURL *url=[NSURL URLWithString:urlAsString];
        NSURLRequest *urlRequest=[NSURLRequest requestWithURL:url];
        
        NSError *err=nil;
        NSData *imagedate=[NSURLConnection sendSynchronousRequest:urlRequest returningResponse:nil error:&err];
        //这个线程休眠5秒
        //
        [NSThread sleepForTimeInterval:5];
        if (err==nil&&imagedate!=nil) {
            image=[UIImage imageWithData:imagedate];
        }
        else if (err!=nil)
        {
            NSLog(@"error ==%@",err);
        }
         self.imageview.image=image;
        
        
    }

    - (IBAction)ShouCang:(id)sender {
    }
    @end

  • 相关阅读:
    根据数组对象中的某个属性值排序
    vue小知识
    vue项目中config文件中的 index.js 配置
    小问题
    原生无缝轮播
    webpack打包提交代码
    echarts
    面试问题
    MySql
    vue-router 跳转原理
  • 原文地址:https://www.cnblogs.com/linximu/p/4446849.html
Copyright © 2011-2022 走看看