• <bdo id='cZfym'></bdo><ul id='cZfym'></ul>

  • <small id='cZfym'></small><noframes id='cZfym'>

    <tfoot id='cZfym'></tfoot>

  • <i id='cZfym'><tr id='cZfym'><dt id='cZfym'><q id='cZfym'><span id='cZfym'><b id='cZfym'><form id='cZfym'><ins id='cZfym'></ins><ul id='cZfym'></ul><sub id='cZfym'></sub></form><legend id='cZfym'></legend><bdo id='cZfym'><pre id='cZfym'><center id='cZfym'></center></pre></bdo></b><th id='cZfym'></th></span></q></dt></tr></i><div id='cZfym'><tfoot id='cZfym'></tfoot><dl id='cZfym'><fieldset id='cZfym'></fieldset></dl></div>
    <legend id='cZfym'><style id='cZfym'><dir id='cZfym'><q id='cZfym'></q></dir></style></legend>

        目标 - C:从 URL 加载图像?

        时间:2024-04-15

        <small id='Pw3q9'></small><noframes id='Pw3q9'>

          • <bdo id='Pw3q9'></bdo><ul id='Pw3q9'></ul>

              <tbody id='Pw3q9'></tbody>

              • <legend id='Pw3q9'><style id='Pw3q9'><dir id='Pw3q9'><q id='Pw3q9'></q></dir></style></legend>

                  <i id='Pw3q9'><tr id='Pw3q9'><dt id='Pw3q9'><q id='Pw3q9'><span id='Pw3q9'><b id='Pw3q9'><form id='Pw3q9'><ins id='Pw3q9'></ins><ul id='Pw3q9'></ul><sub id='Pw3q9'></sub></form><legend id='Pw3q9'></legend><bdo id='Pw3q9'><pre id='Pw3q9'><center id='Pw3q9'></center></pre></bdo></b><th id='Pw3q9'></th></span></q></dt></tr></i><div id='Pw3q9'><tfoot id='Pw3q9'></tfoot><dl id='Pw3q9'><fieldset id='Pw3q9'></fieldset></dl></div>

                1. <tfoot id='Pw3q9'></tfoot>
                  本文介绍了目标 - C:从 URL 加载图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  Sorry for question title. I can not find a suitable title.

                  I have UITableView content images from url when i open the UITableView the View did not show until the images loaded and that takes along time.

                  I get the images from JSON by php.

                  I want to show the table and then images loading process.

                  This is code from my app:

                  NSDictionary *info = [json objectAtIndex:indexPath.row];
                  cell.lbl.text = [info objectForKey:@"title"];
                  NSString *imageUrl = [info objectForKey:@"image"];
                  cell.img.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:imageUrl]]];
                  [cell.img.layer setBorderColor: [[UIColor blackColor] CGColor]];
                  [cell.img.layer setBorderWidth: 1.0];
                  
                  return cell;
                  

                  Sorry my english is weak.

                  解决方案

                  Perform the web request on a separate thread, to not block the UI. Here is an example using NSOperation. Remember to only update the UI on the main thread, as shown with performSelectorOnMainThread:.

                  - (void)loadImage:(NSURL *)imageURL
                  {
                      NSOperationQueue *queue = [NSOperationQueue new];
                      NSInvocationOperation *operation = [[NSInvocationOperation alloc]
                                                          initWithTarget:self
                                                          selector:@selector(requestRemoteImage:)
                                                          object:imageURL];
                      [queue addOperation:operation];
                  }
                  
                  - (void)requestRemoteImage:(NSURL *)imageURL
                  {
                      NSData *imageData = [[NSData alloc] initWithContentsOfURL:imageURL];
                      UIImage *image = [[UIImage alloc] initWithData:imageData];
                  
                      [self performSelectorOnMainThread:@selector(placeImageInUI:) withObject:image waitUntilDone:YES];
                  }
                  
                  - (void)placeImageInUI:(UIImage *)image
                  {
                      [_image setImage:image];
                  }
                  

                  这篇关于目标 - C:从 URL 加载图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何使用 UIImageViewExtension 与 Swift 异步加载图像并防止重复图像或错误图像加载到单元格 下一篇:从 UIImageView 创建 UIImage

                  相关文章

                2. <tfoot id='baX0c'></tfoot>

                3. <small id='baX0c'></small><noframes id='baX0c'>

                    <i id='baX0c'><tr id='baX0c'><dt id='baX0c'><q id='baX0c'><span id='baX0c'><b id='baX0c'><form id='baX0c'><ins id='baX0c'></ins><ul id='baX0c'></ul><sub id='baX0c'></sub></form><legend id='baX0c'></legend><bdo id='baX0c'><pre id='baX0c'><center id='baX0c'></center></pre></bdo></b><th id='baX0c'></th></span></q></dt></tr></i><div id='baX0c'><tfoot id='baX0c'></tfoot><dl id='baX0c'><fieldset id='baX0c'></fieldset></dl></div>
                    • <bdo id='baX0c'></bdo><ul id='baX0c'></ul>
                    <legend id='baX0c'><style id='baX0c'><dir id='baX0c'><q id='baX0c'></q></dir></style></legend>