During the development process, a large amount of data needs to be loaded. For example, the network may be frequently requested to display images.
We cannot refresh the table view after loading all the images !!
How can this problem be solved? I tried the thread several times. Finally solved the problem. It is to send messages to the main thread in the Child thread!
My personal practice is as follows:
First, n images are displayed. n is not too large. N = 5. Place n more images in the Child thread and load them.
If ([array count]> 5)
{
[Self initialize mselectorinbackground: @ selector (show_list_item_in_background :) withObject: array];
}
However, I want to refresh the table view every M images. At this time, we need to do this:
-(Void) show_list_item_in_background :( NSArray *) array
{
Intindex = 5;
Intsecond_run = [array count];
While (index <second_run)
{
NSDictionary * dictionary = [array objectAtIndex: index];
[Self get_and_show_more: dictionary];
Index ++;
If (index> 5 & index % 5 = 0)
{
[Self defined mselec1_mainthread: @ selector (reload_table_view_on_main_thread) withObject: nilwaitUntilDone: NO];
}
}
[Table_view reloadData];
[Activity_view stopAnimating];
}
The main thread calls the reload_table_view_on_main_thread method to refresh the table view.
-(Void) reload_table_view_on_main_thread
{
[Table_view reloadData];
}
From cloud huaikong-abel