我有一个tableview,并且在那个tableview中我设置了customcell。在那个customcell中有一个按钮,当单击按钮时,然后委托调用的方法并播放或暂停音频。
但是我不知道为什么我的方法没有被调用。

这是我的代码。

AudioInfoCell.h //子视图

#import <UIKit/UIKit.h>

@protocol PlayPauseDelegate <NSObject>

-(void)playPauseAudio;

@end

@interface AudioInfoCell : UITableViewCell

{
    id<PlayPauseDelegate> delegate;

}

@property(nonatomic,strong)id delegate;

@end;


AudioInfoCell.m

@synthesize delegate;




- (IBAction)playPauseBtnTapped:(id)sender {

if([delegate respondsToSelector:@selector(playPauseAudio)])
{
    //send the delegate function with the amount entered by the user
    [delegate playPauseAudio];
}
}


AudioTableViewController.h //其父视图

#import "AudioInfoCell.h"

@interface AudioTableViewController : UIViewController<PlayPauseDelegate>


AudioTableViewController.m

cell.delegate = self;

-(void)playPauseAudio{
NSLog(@"button pressed");
}

最佳答案

@kartik,我尚未指定使用哪种方法指定cell.delegate=self;

所以我假设您已经在viewDidLoad中指定了它,而不是在vieWillApear方法中指定了它而不是它应该工作。

10-07 19:41
查看更多