我刚刚创建了一个带有Audioplayer接口的Xib(播放按钮,停止按钮,音量滑块,时间滑块)。我将Files所有者连接到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
第三卷滑块:
ViewController .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
ViewController .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];
}
玩家XIB: 我想了几个小时,但我不知道任何解决方案,所以也许你可以帮助我......
答案 0 :(得分:0)
您的代码保留了AudioPlayerViewController
视图(因此保留了所有子视图),但它没有保留audiov
实例。因此,当任何视图触发其操作时,它们将调用已解除分配的实例。
要解决此问题,请创建一个属性并存储audiov
(以便保留它)。