Objective C code problem
Posted: Sat Nov 17, 2007 11:01 am
ok here is my problem. i am building a application that will open .txt files, you can then edit them and save them. the save function works, the editing works, but i cannot get it to open them. I am writing this in Objective C and whenever i try to open a .txt file it crashes the application. I am building this in Xcode. Here is the code i am using:
Code: Select all
- (IBAction)openTextFile:(id)sender
{
NSOpenPanel *theOpenPanel = [NSOpenPanel openPanel];
if ([theOpenPanel runModal] == NSOKButton)
{
NSString *theFileName = [theOpenPanel filename];
NSString *theFileContents = [NSString stringWithContentsOfFile:theFileName];
[theTextView setString:theFileContents];
[theFileName release];
[theFileContents release];
}
}