Delayed initialization pointer address nstimer

Source: Internet
Author: User

A lot of things are a little uncomfortable. Here, Mark

First, delayed Initialization

First

 
@ Property (retain, nonatomic) nsmutablearray * buttonsarray;
 
@ Synthesize buttonsarray;

 
// Mark code-(nsmutablearray *) buttonsarray {If (! Buttonsarray) {buttonsarray = [[nsmutablearray alloc] init];} return buttonsarray ;}

 
Uinewsdetailplayview * newsdetailplayview = [[uinewsdetailplayview alloc] initfromnib]; [self. buttonsarray addobject: newsdetailplayview];

Add the object to the array, that is, to save the pointer.

 
For (uinewsdetailplayview * detailplayview in self. buttonsarray) {[detailplayview. playbutton setselected: No]; // retrieve playbutton and set the selected state}

Why do you want to write it like this? An error occurred while manually adding an event to a button.CodeAs follows:

 
[Newsdetailplayview. playbutton addtarget: Self action: @ selector (playaudio :) forcontrolevents: uicontroleventtouchupinside];

However, when playaudio declares an nstdio, you cannot perform the following operations on playbutton:

-(Void) playaudio :( uibutton *) button {int audioflag = button. tag-play_button_root_tag; nsarray * List = [self. newsdata. programamedia componentsseparatedbystring: @ ","]; nsstring * mediaurl = [list objectatindex: audioflag]; If (button. selected) {[[mmsplayer sharedmmsplayer] Stop]; [Button setselected: No]; isplaying = false;} else {[self startloadinganimation]; [[mmsplayer sharedmmsplayer] Play: mediaurl]; [Button setselected: Yes]; isplaying = true; // mark code [[nstimer scheduledtimerwithtimeinterval: 10 target: Self selector: @ selector (handletimer :) userinfo: Nil repeats: no] retain] ;}}- (void) handletimer :( nstimer *) timer {// mark code for (uinewsdetailplayview * detailplayview in self. buttonsarray) {[detailplayview. playbutton setselected: No];} [alertutils alertwithmessage: @ "buffer timeout check whether network resources are available"]; [[mmsplayer sharedmmsplayer] Stop]; [self stoploadinganimation]; [Timer release];}

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.