Iphone development: reloadData refresh by thread

Source: Internet
Author: User

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

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.