For more buttons on the UITableViewCell, click to play the audio and want to change the button state after the audio playback is complete:

Source: Internet
Author: User

First of all, this method is really very cow, it is better to ingenious:

In this app to do foodie, because we need to add a button on the UITableViewCell, when you click on this button to start playing audio (while the button status changed to selected), these processing is OK, But now the problem is that when the audio playback is complete, a proxy method is triggered (that is, telling the audio to be played

-(void) audioplayerdidfinishplaying: (Avaudioplayer *) player successfully: (BOOL) flag), how do I change the state of the button in this method:

Chat with the group of Brothers to know, I can define a global button, and then assign this button in the cell to the global button, when the audio playback is complete, in that proxy method to write button.selected = NO;






My code implementation is like this, just intercept fragments here:

In the. h file:

UIButton *btn;

@property (Nonatomic,retain) UIButton *btn;

In the. m file:

First-(void) The Dealloc method writes:

if (BTN) {//This place is what I have mentioned in the next article if not sure will be created, then in the Delloc release in the best judgment

[BTN release];

BTN = nil;

}

[Super Dealloc]; }


In

-(UITableViewCell *) TableView: (UITableView *) Tableviewdemo Cellforrowatindexpath: (Nsindexpath *) Indexpath In this method, the button of the cell is assigned to the global button:

SELF.BTN = Cell.audioinfobutton;



You can then change the status of the button in the proxy class where the audio playback is completed:

-(void) audioplayerdidfinishplaying: (Avaudioplayer *) player successfully: (BOOL) Flag {

NSLog (@ "play complete");

self.btn.selected = NO;


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.