我對這個錯誤感到瘋狂。編譯器正在超出實例NSSString變量的範圍。以前從未有過這件事,並使用了數千個NSString實例變量!iPhone SDK - 超出範圍問題的實例變量
這裏是我的類.h文件中
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#import <CoreAudio/CoreAudioTypes.h>
#import "Snapshot.h"
@interface RecordAudioViewController : UIViewController <AVAudioRecorderDelegate, AVAudioPlayerDelegate> {
NSString *filename;
}
@property (nonatomic, retain) NSString *filename;
- (IBAction) recordAudio;
- (IBAction) playAudio;
@end
變正常合成。我在viewDidLoad方法中初始化文件名變量。我想在IBAction方法recordAudio中使用它,但編譯器總是說超出範圍?爲什麼呢,這是一個錯誤還是什麼?
這裏是.m代碼。 viewDidLoad方法,其中我設置文件名實例變量:
- (void)viewDidLoad {
[super viewDidLoad];
的NSString * TMPDIR = NSTemporaryDirectory(); filename = [NSString stringWithFormat:@「%。0f。%@」,[NSDate timeIntervalSinceReferenceDate] * 1000.0,@「caf」]; NSLog(filename); }
而且IBAction爲方法
- (IBAction) recordAudio
{
NSLog(filename); // here I get out of scope message when moving over with mouse cursor and when steping over this line EXC_BAD_ACCESS
}
整個.m文件可以在這裏看到:http://pastie.org/1021993
我們可以看到.m文件的代碼嗎?這是一個bug,但最可能是你的。 :-) – Eiko 2010-06-28 10:48:33
@Eiko:我在原帖中添加了代碼。我做了這一千次,我沒有看到我可能出錯的地方。您可以在這裏看到整個.m文件:http://pastie.org/1021993 – 2010-06-28 16:22:01
您需要明確保留變量或讓屬性的語法糖做到這一點 - 請參閱mharper的答案。 – Eiko 2010-06-28 20:40:51