IOS learning: uitableview 2 (pull-down refresh)

Source: Internet
Author: User

 

1/* 2 implement the drop-down refresh of tableview 3 will this method be triggered when tableview slides? 4 */5-(void) tableview :( uitableview *) tableview willdisplaycell :( uitableviewcell *) cell forrowatindexpath :( nsindexpath *) indexpath 6 {7 // triggers 8 If (indexpath. row = self. m_data.count-1) {9 10 // define a uiview 11 uiview * footspinnerview = [[uiview alloc] initwithframe: cgrectmake (0.0f, 0.0f, 3201_f, 601_f)]; 12 13 // view 14 uiactivityindicatorview * Activity = [[refreshing alloc] initwithframe: cgrectmake (130.0f, 0.0f, 601_f, 601_f)]; 15 activity. color = [uicolor redcolor]; 16 [activity startanimating]; // start view 17 18 footspinnerview. backgroundcolor = [uicolor graycolor]; 19 [footspinnerview addsubview: activity]; 20 21 // set footerview 22 self. mytableview. tablefooterview = footspinnerview; 23 24 // self. mytableview. tableheaderview = footspinnerview; 25 26 dispatch_queue_t queue = dispatch_queue_create ("My queue", nil); 27 28 // Add data 29 dispatch_async (queue, ^ (void) to the background thread) {30 31 [self. m_data addobject: @ "1000"]; 32 [self. m_data addobject: @" 1001 "]; 33 [self. m_data addobject: @ "1002"]; 34 [self. m_data addobject: @ "1003"]; 35 [self. m_data addobject: @ "1004"]; 36 37}); 38 39 // reload the data after adding the data 40 dispatch_async (queue, ^ (void) {41 42 sleep (2); 43 dispatch_sync (dispatch_get_main_queue (), ^ (void) {44 45 [self. mytableview reloaddata]; 46}); 47}); 48 49 // [self. mytableview reloaddata]; 50 dispatch_release (Queue); 51 [footspinnerview release]; 52 [activity release]; 53} 54 // else if (indexpath. row = 0) {55 // 56 // uiview * footspinnerview = [[uiview alloc] initwithframe: cgrectmake (0.0f, 0.0f, 32020.f, 601_f)]; 57 // uiactivityindicatorview * Activity = [[uiactivityindicatorview alloc] initwithframe: cgrectmake (130.0f, 0.0f, 601_f, 601_f)]; 58 // activity. color = [uicolor redcolor]; 59 // [activity startanimating]; 60 // 61 // footspinnerview. backgroundcolor = [uicolor graycolor]; 62 // [footspinnerview addsubview: activity]; 63 // 64 // self. mytableview. tablefooterview = footspinnerview; 65 // 66 // self. mytableview. tableheaderview = footspinnerview; 67 // 68 // dispatch_queue_t queue = dispatch_queue_create ("My queue", nil); 69 // 70 // dispatch_async (queue, ^ (void) {71 // 72 // [self. m_data insertobject: @ "1000" atindex: 0]; 73 // [self. m_data addobject: @ "1001"]; 74 // [self. m_data addobject: @ "1002"]; 75 /// [self. m_data addobject: @ "1003"]; 76 /// [self. m_data addobject: @ "1004"]; 77 // [self. m_data insertobject: [nsarray arraywithobject: @ "01"] atindex: 0]; 78 // 79 //}); 80 // 81 // dispatch_async (queue, ^ (void) {82 // 83 // sleep (2); 84 // dispatch_sync (dispatch_get_main_queue (), ^ (void) {85 // 86 // [self. mytableview reloaddata]; 87 // [self. mytableview scrolltorowatindexpath: [indexpath initwithindex: 3] atscrollposition: uitableviewscrollpositionnone animated: Yes]; 88 //}); 89 //}); 90 // 91 // 92 // dispatch_release (Queue); 93 // [footspinnerview release]; 94 // [activity release]; 95 //} 96 97 // if it is not the last row, set both footerview and headerview to nil 98 else 99 {100 self. mytableview. table footerview = nil; 101 self. mytableview. tableheaderview = nil; 102} 103}

 

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.