When I recently developed a project, I discovered that when I got the data from the Internet, the panic occurred when I used the notification method to refresh the list.
After searching the internet for many articles, it is recommended to use the asynchronous Update method, but still crashes.
Finally, try using the Performselectoronmainthread method to successfully update the TableView.
Let's learn this function now!
The Performselectoronmainthread and Performselectorinbackground of the NSObject class enable simple multithreaded programming techniques
1,-(void) Performselectorinbackground: (SEL) Aselector withobject: (ID) arg
Creates a thread that executes on a child thread, Aselector represents the newly created thread, and ARG is the parameter passed in
2,-(void) Performselectoronmainthread: (SEL) Aselector withobject: (ID) arg waituntildone: (BOOL) wait;
The function of this method is to execute the developed method (code block) in the main thread.
Parameters:
@selector is to define the method that we want to execute.
Withobject:arg defines the parameter object that is passed in when we execute the method. The type is the ID. (We can pass in any parameter)
WAITUNTILDONE:YES Specifies whether the current thread will be blocked until the main thread finishes executing the block of code we have made.
Attention:
1. The Waituntildone:yes parameter is not valid when the current thread is the main path.
2. The method, no return value
3. This method is mainly used to modify the state of the page UI with the main thread.
Try using the Performselectoronmainthread method when iOS updates the UI