我正在製作一個詩歌應用程序,用戶可以在其中編寫詩歌並將其保存到文件中。當我點擊UITextView添加和編輯文本時,它立即導致EXC_BAD_ACCESS。有人可以幫我解釋爲什麼會發生這種情況。EXC_BAD_ACCESS問題
這是我在.h文件
#import <UIKit/UIKit.h>
@interface SecondViewController : UIViewController {
UITextView *newPoemTextView;
UIImageView *newPoemTextViewBackground;
}
@property (nonatomic, retain) IBOutlet UITextView *newPoemTextView;
@property (nonatomic, retain) IBOutlet UIImageView *newPoemTextViewBackground;
-(IBAction)closeKeyboard;
@end
,這就是我在.m文件
@implementation SecondViewController
@synthesize newPoemTextView;
@synthesize newPoemTextViewBackground;
-(IBAction)closeKeyboard {
// This part will write the information to the file
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [documentPaths objectAtIndex:0];
NSString *documentTXTPath = [documentsDirectory stringByAppendingPathComponent:@"savedText.txt"];
NSString *savedString = newPoemTextView.text;
[savedString writeToFile:documentTXTPath atomically:YES];
//This part hopefully closes the keyboard correctly, cross fingers
[newPoemTextView resignFirstResponder];
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
UIImage *image = [UIImage imageNamed: @"newPoemBackground.png"];
[newPoemTextViewBackground setImage:image];
UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage
imageNamed:@"background.png"]];
self.view.backgroundColor = background;
[background release];
[super viewDidLoad];
}
只是讓你知道'newPoemTextViewBackground'永遠不會被合成。 – Joe 2011-05-03 17:57:15
補充說,現在,但它仍然給我同樣的錯誤,當keyboad打開。 – 2011-05-03 18:16:38
**如果發生崩潰,請發回追蹤。** – bbum 2011-05-03 20:27:21