爲什麼不是這個代碼工作?該應用程序加載罰款,但是每當我按下按鈕應用程序鎖定(不會崩潰),並將我返回給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.
}
它看起來像.m文件中的Matlab代碼。在matlab中,你不需要初始化變量。 – 2009-07-30 18:40:31
是什麼? soundArray沒有任何內容,通過上面的代碼即 – Daniel 2009-07-30 18:45:02