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