MJ-0918-network programming 1

Source: Internet
Author: User

Instance: Application List (network image retrieval)

 

1. Create tableviewcontroller

2. Import the plist of the app

3. Import the model of the APP (Save the template file)

4. Write apps in the Controller for lazy loading (fast code addition)

5. Set the number of rows in the list.

 

6. Create a cell (fast code addition)

7. Assign the detailtitle and title values to the cell.

8. Enable sub-threads to set imageview

8.1 disadvantages of Direct setting

1. The main thread is blocked, causing no response to the UI operation.

2. Duplicate downloads, wasting resources and traffic

8.2 lazy loading and creating a queue

Create operation object and download Image

Problem: you cannot download it again after the download fails.

Solution: Create a storage operation and URL dictionary and create a one-to-one correspondence

 

Problem: Repeated download

Solution: Determine whether the downloading operation has been successful and whether the downloading operation exists in the dictionary.

Problem: The imageview size is not set during cell initialization and cannot be displayed, or the cell content is cached when the cell is reused, misleading users

Solution: Use bitmap

Problem: The image has not been downloaded yet, and its cell is reused. If the current image to be downloaded is faster, the previously downloaded image will overwrite the current image, imageview image Setting Order: Image proportion-> current image-> previous image

Solution: instead of directly setting imageview. Image, refresh the table and set it through the content in the dictionary.

Question: How to refresh a table and waste memory resources?

Solution: refresh a single row

Problem: too many images may cause memory alarms.

Solution: 1. Release the dictionary,

2. Start to drag and drop to suspend the queue, and end to drag and drop to restore the queue

Problem: circular reference between xxviewcontroller, queue, and Operation

Solution: Use viewcontroller's weak pointer object

Or

Problem: The dictionary key cannot be nil. When an image download failure returns NULL, the program will crash.

Solution:

 

 

############################### ##############

Uiimage-> nsdata-> File

 

Caches does not back up or automatically clean up, and is used to store memory-occupied resources.

 

Full path must be used on mobile phones

 

Store images in sandbox

 

Retrieve the image in the sandbox

 

 

 

Encapsulation of the download process, the Controller only needs to call

1. Create an image download proxy

2. Create a proxy

3. Create the URL and indexpath attributes

4. The controller sets the URL and indexpath.

5. Set the Controller as a proxy.

6. Implement proxy Methods

7. Obtain an image

 

 

The time-consuming operation may be canceled midway through. You need to terminate the proxy method and respond to the cancellation operation.

 

 

 

Sdwebimage framework (master)

 

Cache Management

 

Default Maximum Cache Time: one week

Default Maximum Cache capacity: Not Set

 

 

Network Programming Overview

HTTP request Scheme

Apple native

Nsurlconnection

Nsurllession

Cfnetwork

 

Third-party framework

Asihttprequest

Afnetworking

Mknetworkkit

 

 

 

Expand knowledge points

1.

2. All objects used in the block will be strongly referenced, because the block code is not sure when it will be called.

3.

4. xxappdelegate monitors the entire project

 

MJ-0918-network programming 1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.