Loading images in background to optimize the loading in ios

后端 未结 9 1391
星月不相逢
星月不相逢 2021-02-02 03:02

I am trying to optimize the load in my application, in fact, I have a lot of images that loaded in my application, and I spend a lot of time waiting for a view controller to ope

9条回答
  •  不要未来只要你来
    2021-02-02 03:25

    To enable the app while getting the images from server and disable block while loading the images try to use UIImageView+AFNetworking library to load the image from server asynchronously AFNetworking

       NSString *imageUrl = [[dict objectForKey:@"photo"] objectForKey:@"url"];
    
       UIImageView *myImage = [[UIImageView alloc] init];
    
       [myImage setImageWithURL:[NSURL URLWithString:imageUrl] placeholderImage:[UIImage    imageNamed:@"PlaceHolder.png"]];
    

    Just add this library and include the UIImageView+AFNetworking so you can use the new UIImageView Category imageWithUrl

提交回复
热议问题