【发布时间】:2009-07-30 18:26:35
【问题描述】:
为什么这段代码不起作用?应用程序加载正常,但是每当我按下按钮时,应用程序就会锁定(不会崩溃)并将我返回到 Xcode,并且有一个红色箭头指向其中一行(如下行所示)。
我还收到三个警告(不是错误),一个说“NSMutableArray”可能无法响应“-objectAt:”,第二个说未使用变量“soundToPlay”第三个说隐式声明函数“AudioServicesPlaySystemSound”我应该关心那些?
//In MainViewController.h
@interface MainViewController : UIViewController {
IBOutlet UIButton *Button;
}
@property (nonatomic, retain) UIButton *Button;
- (IBAction)playSound;
NSInteger currentSound;
NSMutableArray *soundArray;
@end
//In MainViewController.m
- (void)viewDidLoad {
currentSound = 0;
NSMutableArray *sounds = [[NSMutableArray alloc] init];
[sounds addObject: @"0.wav"];
[sounds addObject: @"1.wav"];
[sounds addObject: @"2.wav"];
[sounds addObject: @"3.wav"];
[sounds addObject: @"4.wav"];
[sounds addObject: @"5.wav"];
[sounds addObject: @"6.wav"];
[sounds addObject: @"7.wav"];
[sounds addObject: @"8.wav"];
[sounds addObject: @"9.wav"];
[sounds addObject: @"10.wav"];
[sounds addObject: @"11.wav"];
[sounds addObject: @"12.wav"];
[sounds addObject: @"13.wav"];
[super viewDidLoad];
}
- (IBAction)playSound {
NSString *soundToPlay = [soundArray objectAt: currentSound];
//First two errors here.
currentSound = (currentSound + 1) % [soundArray count]; //Red arrow points to this line.
AudioServicesPlaySystemSound (currentSound);
//Third error here.
}
【问题讨论】:
标签: iphone objective-c arrays