1.UITableview optimization methods (cache height, asynchronous rendering, reduced hierarchy, hide, avoid off-screen rendering)

Cache height: When we calculate the height of the cell when creating the frame model, we can cache the height of the cell into the dictionary, using the indexpath and Identifier of the cell as the key. **1. NSString *key = [[HeightCache shareHeightCache] makeKeyWithIdentifier:@”YwywProductGradeCell” indexPath:indexPath];

  1. if ([[HeightCache shareHeightCache] existInCacheByKey:key]) {
  2. return [[HeightCache shareHeightCache] heightFromCacheWithKey:key];
  3. }else{
  4. YwywProductGradeModelFrame *modelFrame = self.gradeArray[indexPath.row];
  5. [[HeightCache shareHeightCache] cacheHieght:modelFrame.cellHight key:key];
  6. return modelFrame.cellHight;
  7. }

** Asynchronous drawing, reduce the hierarchy: create all the controls you may need, and hide or show them according to the situation. Avoid off-screen rendering: Use Layer directly whenever you are not using both borders/border colors and rounded corners. Will not cause off-screen rendering.

Why does AFN add a resident thread?

AFN purpose: is to open up threads to request network data. If we don’t have a resident thread, we will create a thread every time we request the network, and then destroy the resident thread, which will cause a waste of resources. We can avoid this waste by creating a resident thread, which can be added to this thread every time we make a network request.

Use of.KVO? How does it work? (Why create subclasses to implement)

Kvo: Key value observation, according to the key corresponding to the change of the value, to call the method. Registered observers: addObserver: forKeyPath: options: context: implement observer: observeValueForKeyPath: ofObject: change: context: Remove observer: RemoveObserver: forKeyPath: (object is destroyed, must remove the observer) pay attention to use kvo monitoring object, A monitor is not the nature of the object, A system to create an intermediate object NSKVONotifying_A and inherit A object, And the isa pointer to the object A does not point to the class of A, but to the object NSKVONotifying_A \

What is objective-C Runtime?

Objective-c Runtime is a Runtime Library, which is a Library written primarily in C and assembly that adds the ability to face objects to C and creates Objective-C. This means that it is loaded in Class information and does all method distribution, method forwarding, and so on. The Objective-C Runtime creates all the structures needed to make programming objective-C faces possible.

GCD implementation queue group type

  • (void) methodone{

dispatch_group_t group = dispatch_group_create();

dispatch_group_async(group, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSLog(@”%d”,1); });

dispatch_group_async(group, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSLog(@”%d”,2); });

dispatch_group_notify(group, dispatch_get_main_queue(), ^{ NSLog(@”3″);

dispatch_group_t group1 = dispatch_group_create();

dispatch_group_async(group1, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    NSLog(@"%d",4);
});

dispatch_group_async(group1, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    NSLog(@"%d",5);
});
Copy the code

});

}

The main queue is the serial queue that comes with GCD and executes in the main thread. Asynchronous global concurrent queue starts new threads that execute concurrently.

In parallel queues, synchronous tasks are started in order of execution. Only asynchronous tasks have no order.

Serial queues start asynchronous tasks in order.

Deadlock caused by nested synchronous tasks after asynchronous tasks were enabled in a serial queue.

Static action?

(1) The static variable ranges from the body of the function. Unlike the auto variable, the memory of the static variable is allocated only once. Therefore, the value of the static variable remains the same as the value of the last call.

(2) Static global variables within a module can be accessed by functions within the module, but not by functions outside the module;

(3) Static functions in a module can only be called by other functions in the module. The scope of use of this function is limited to declarations

Its module;

(4) Static member variables in a class are owned by the entire class, and there is only one copy of all objects in the class;

(5) A static member function in a class belongs to the entire class. This function does not receive this pointer, and therefore can only access static member variables of the class. — — — — — — — —

Network module:

The history of HTTP and the HTTPS encryption process relative to HTTP

2. What are the differences and connections between TCP and UDP?

3. Where does the timeout of HTTP start by default

4. Does HTTP use UDP or TCP links and must TCP links be established every time an HTTP request is sent? Why

Q: Does TCP have a four-way handshake? Does TCP have a three-way handshake?

6. Why four handshakes?

7, TCP establishes several channels, what are they, the sender and receiver are the same channel? — — — — — — — —

.RunLoop Running mode

RunLoop runs in one of five modes. To switch modes, you have to pause the current mode and override the starting one

1 kCFRunLoopDefaultMode, the default running mode of the App. Usually the main thread runs in this running mode

2 UITrackingRunLoopMode, tracking user interaction events (used for ScrollView tracking touch sliding, to ensure that the interface sliding is not affected by other modes)

3 kCFRunLoopCommonModes, pseudo-mode, is not a real mode of operation

4 UIInitializationRunLoopMode: when just start the App the first to enter the first Mode,

5 GSEventReceiveRunLoopMode: accept system internal event, is usually not used

. Runloop internal logic?

  • In fact, RunLoop is just such a function, with a do-while loop inside. When you call CFRunLoopRun(), the thread stays in the loop; This function does not return until it times out or is manually stopped.

    \

. Runloop internal logic?

  • In fact, RunLoop is just such a function, with a do-while loop inside. When you call CFRunLoopRun(), the thread stays in the loop; This function does not return until it times out or is manually stopped.

    \

. Runloop internal logic?

  • In fact, RunLoop is just such a function, with a do-while loop inside. When you call CFRunLoopRun(), the thread stays in the loop; This function does not return until it times out or is manually stopped.

    \

. Runloop internal logic?

  • In fact, RunLoop is just such a function, with a do-while loop inside. When you call CFRunLoopRun(), the thread stays in the loop; This function does not return until it times out or is manually stopped.

    \

How to use Runloop in AFNetworking? AFURLConnectionOperation the AFURLConnectionOperation class is built on NSURLConnection and is expected to receive a Delegate callback in a background thread. AFNetworking created a separate thread for this purpose and started a RunLoop in that thread:

  • (void)networkRequestThreadEntryPoint:(id)__unused object { @autoreleasepool { [[NSThread currentThread] setName:@”AFNetworking”]; NSRunLoop *runLoop = [NSRunLoop currentRunLoop]; [runLoop addPort:[NSMachPort port] forMode:NSDefaultRunLoopMode]; [runLoop run]; }

}

  • (NSThread *)networkRequestThread { static NSThread *_networkRequestThread = nil; static dispatch_once_t oncePredicate; dispatch_once(&oncePredicate, ^{ _networkRequestThread = [[NSThread alloc] initWithTarget:self selector:@selector(networkRequestThreadEntryPoint:) object:nil]; [_networkRequestThread start]; }); return _networkRequestThread;

}

That’s all for today. It’s been a while. Please keep an eye on it

【 Tencent documents 】 more information sharing docs.qq.com/doc/DZXpKSU…