IOS Practice BLOCK Calls

Source: Internet
Author: User

firsttypedef void (^tellpicblock) (NSString *albumpic);//typedef definition block@interface Personprofileviewcontroller: Uitableviewcontroller @property (nonatomic,copy) Tellpicblock tblock;//declares a block named Tblock

Call block at the right time, for example, when playing music, from the data model to remove the stored Albumpic address, notify the PLAYINGVC class this image address information

if (_tblock) {self.        Tblock (Pmusuic.albumpic);    or _tblock (pmusuic.albumpic); }

Here is the concrete way to implement this block in PLAYINGVC, (NSString *albumpic) is the picture information passed from the PPVC class.

No return value of the block call implementation, receive album Image     ///no return value of the block call implementation, receive album Pictures     __weak  playingvc *pvc = self;//to avoid circular references need to develop weak pointers     self.ppvc.TBlock =    ^ (nsstring *albumpic) {                 dispatch_async (Dispatch_get_global_queue (dispatch_queue_priority_default, 0 ),  ^{            nslog (@ "received album Picture%@", AlbumPic) ;             nsurl *urlalbum = [ nsurl urlwithstring:albumpic];             nsdata *imgdata = [nsdata datawithcontentsofurl:urlalbum];                          dispatch_async (Dispatch_Get_main_queue (), ^{                                 [ pvc.imgv setimage:[uiimage imagewithdata:imgdata]];                 pvc.imgv.contentMode =  uiviewcontentmodescaleaspectfit;                             });                     })  ;            };


Print Result: 2015-06-02 22:21:55.793 myfm[10974:105677] received album picture http://image.kaolafm.net/mz/images/201403/ Addd221d-7952-46c5-bc52-3f1d5da8a2b0/default.jpg2015-06-02 22:21:55.794 myfm[10974:102918] album picture is/http Image.kaolafm.net/mz/images/201403/addd221d-7952-46c5-bc52-3f1d5da8a2b0/default.jpg



IOS Practice BLOCK Calls

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.