Я создаю поэтическое приложение, в котором пользователи могут писать свои стихи и сохранять их в файл.Когда я нажимаю на UITextView, чтобы добавить и отредактировать текст, он немедленно вызывает 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];
}