0

我刚刚创建了一个带有音频播放器接口的 Xib(播放按钮、停止按钮、音量滑块、时间滑块)。我将文件所有者连接到 AudioPlayerViewController,并通过连接到 ViewController 从 Objects 和 IB Action 创建了一些 Outlets。

现在我将此 ViewControllers 视图添加为 UIScrollview 中的子视图。如果我现在使用这些对象之一,我会收到不同的错误:

首先是时间滑块。值已更改的 IBAction 存在:

 2013-06-23 14:14:55.448 Bookshelf[17323:907] -[__NSMallocBlock__ CurrentPlayTimeChanged:]: unrecognized selector sent to instance 0x1dd69500
2013-06-23 14:14:55.450 Bookshelf[17323:907] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSMallocBlock__ CurrentPlayTimeChanged:]: unrecognized selector sent to instance 0x1dd69500'
*** First throw call stack:
(0x31e1d2a3 0x39cd897f 0x31e20e07 0x31e1f531 0x31d76f68 0x33d100c5 0x33d10077 0x33d10055 0x33d0f90b 0x33df0d07 0x33d0f507 0x33c2e421 0x31df26cd 0x31df09c1 0x31df0d17 0x31d63ebd 0x31d63d49 0x3592f2eb 0x33c79301 0x680dd 0x3a10fb20)
libc++abi.dylib: terminate called throwing an exception

第二个按钮:

2013-06-23 14:16:36.842 Bookshelf[17339:907] -[__NSArrayM AudioStopped:]: unrecognized selector sent to instance 0x1fdb1480
2013-06-23 14:16:36.844 Bookshelf[17339:907] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM AudioStopped:]: unrecognized selector sent to instance 0x1fdb1480'
*** First throw call stack:
(0x31e1d2a3 0x39cd897f 0x31e20e07 0x31e1f531 0x31d76f68 0x33d100c5 0x33d1014d 0x33d100c5 0x33d10077 0x33d10055 0x33d0f90b 0x33d0fe01 0x33c385f1 0x33c25801 0x33c2511b 0x359305a3 0x359301d3 0x31df2173 0x31df2117 0x31df0f99 0x31d63ebd 0x31d63d49 0x3592f2eb 0x33c79301 0xa0dd 0x3a10fb20)
libc++abi.dylib: terminate called throwing an exception

第三音量滑块:

在此处输入图像描述

视图控制器 .h :

#import <UIKit/UIKit.h>

@interface AudioPlayerViewController : UIViewController {
    NSURL * fileURL;
}

@property (weak, nonatomic) IBOutlet UISlider *volumeSlider;
@property (weak, nonatomic) IBOutlet UIBarButtonItem *AudioStopButton;
@property (weak, nonatomic) IBOutlet UIBarButtonItem *AudioPlay_PauseButton;
@property (weak, nonatomic) IBOutlet UIBarButtonItem *AudioTimeLabel;
@property (weak, nonatomic) IBOutlet UISlider *TimeLineSlider;

@property (nonatomic, strong) NSURL * fileURL;


- (IBAction)volumeChanged:(id)sender;
- (IBAction)AudioStopped:(id)sender;
- (IBAction)AudioPlayPaused:(id)sender;
- (IBAction)TimeLabelPressed:(id)sender;
- (IBAction)CurrentPlayTimeChanged:(id)sender;


@end

视图控制器 .m :

#import "AudioPlayerViewController.h"

@interface AudioPlayerViewController ()

@end

@implementation AudioPlayerViewController
@synthesize volumeSlider, AudioPlay_PauseButton, TimeLineSlider, AudioTimeLabel, AudioStopButton;
@synthesize fileURL;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{

    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)volumeChanged:(id)sender {
    NSLog(@"NEW VOL");

}

- (IBAction)AudioStopped:(id)sender {
    NSLog(@"STOP");

}

- (IBAction)AudioPlayPaused:(id)sender {
    NSLog(@"PLAY");
}

- (IBAction)TimeLabelPressed:(id)sender {
    NSLog(@"TIMELABEL");

}

- (IBAction)CurrentPlayTimeChanged:(id)sender {
    NSLog(@"NEW TIME POS");

}
@end

添加子视图的 .m 方法:

- (void) addAudio_index:(int)index {
    AudioPlayerViewController *audiov = [[AudioPlayerViewController alloc] init];
    CGRect frame_s = [[[ScrollView subviews] objectAtIndex:[[ScrollView subviews] count]-1] frame];
    CGRect frame = audiov.view.frame;
    frame.origin.y = frame_s.size.height+frame_s.origin.y;
    frame.origin.x = 0;
    //[audiov.view setFrame:frame];
    UIView *n =[[UIView alloc]initWithFrame:frame];
    [ScrollView addSubview:n];
    [n addSubview:audiov.view];
    [audiov.view setHidden:FALSE];


}

The Player XIB: 在此处输入图像描述 我想了几个小时,但我不知道任何解决方案,所以也许你可以帮助我......

4

1 回答 1

0

您的代码保留了AudioPlayerViewControllers 视图(因此保留了所有子视图),但没有保留audiov实例。因此,当任何视图触发它们的操作时,它们都会调用一个已被释放的实例。

要解决此问题,请创建一个属性并存储audiov(以便保留)。

于 2013-06-23T12:30:31.743 回答