• Apfeltalk ändert einen Teil seiner Allgemeinen Geschäftsbedingungen (AGB), das Löschen von Useraccounts betreffend.
    Näheres könnt Ihr hier nachlesen: AGB-Änderung
  • Was gibt es Schöneres als den Mai draußen in der Natur mit allen Sinnen zu genießen? Lasst uns teilhaben an Euren Erlebnissen und macht mit beim Thema des Monats Da blüht uns was! ---> Klick

Anfänger mit Problem

nylo

Erdapfel
Registriert
23.07.10
Beiträge
1
Hi All,

nachdem ich ausgiebig die SuFu penetriert habe komme ich an dieser stelle nicht mehr weiter... evtl mangelt es am objective c know how :mad:

Ok hab da ne App die die Aufgabe hat einen Text zu speichern und beim starten automatisch zu laden...

Mein Problem liegt darin dass das App nach dem drücken von dem Save Button crasht! - Jedoch speichert die App den text ab und läd ihn beim start wieder...

SaveTextAppDelegate.h
Code:
//
//  SaveTextAppDelegate.h
//  SaveText
//
//  Created by nylo on 22.07.10.
//  Copyright - 2010. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface SaveTextAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
    UIButton *saveButton;
    UITextView *textView;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UIButton *saveButton;
@property (nonatomic, retain) IBOutlet UITextView *textView;

- (IBAction)saveButtonClicked:(id)sender;

@end
SaveTextAppDelegate.m
Code:
//
//  SaveTextAppDelegate.m
//  SaveText
//
//  Created by nylo on 22.07.10.
//  Copyright - 2010. All rights reserved.
//

#import "SaveTextAppDelegate.h"

#define FILE_PATH [NSHomeDirectory() stringByAppendingPathComponent:@"ownText.txt"]

@implementation SaveTextAppDelegate

@synthesize window;
@synthesize textView, saveButton;


#pragma mark -
#pragma mark Application lifecycle

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    
    BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:FILE_PATH];
    
    if(!fileExists){
        textView.text = @"Schreib mal was!";
        
    } else {    
        
        NSString *text = [NSString stringWithContentsOfFile:FILE_PATH encoding:NSUTF8StringEncoding error:nil];[NSString stringWithContentsOfFile:FILE_PATH encoding:NSUTF8StringEncoding error:nil];        
        textView.text = text;
    }
        
    // Override point for customization after application launch.
    
    [window makeKeyAndVisible];
    
    return YES;
}


- (IBAction)saveButtonClicked:(id)sender {
    NSLog(@"saveButtonClicked");    
    NSString *textToSave = [textView text];
    [textToSave writeToFile: FILE_PATH atomically:YES encoding:NSUTF8StringEncoding error:nil];

}


- (void)applicationWillResignActive:(UIApplication *)application {
    /*
     Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
     Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
     */
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
    /*
     Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
     If your application supports background execution, called instead of applicationWillTerminate: when the user quits.
     */
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    /*
     Called as part of  transition from the background to the inactive state: here you can undo many of the changes made on entering the background.
     */
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    /*
     Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
     */
}


- (void)applicationWillTerminate:(UIApplication *)application {
    /*
     Called when the application is about to terminate.
     See also applicationDidEnterBackground:.
     */
}


#pragma mark -
#pragma mark Memory management

- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
    /*
     Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
     */
}


- (void)dealloc {
    [textView release];
    [saveButton release];
    [window release];
    [super dealloc];
}


@end
Ich kann meinen Fehler einfach nicht finden!!!

THX im Vorraus!
 

Angel3DWin

Gala
Registriert
10.03.10
Beiträge
50
Hilfreich wäre, wenn du den Fehlertext in der Konsole rauskopieren könntest, dann wüsste man auch genauer, was crasht.
 

Sebastato

Jonagold
Registriert
04.07.10
Beiträge
18
Du kannst nicht direkt in Dein HomeDirectory schreiben. Die App läuft in einer Sandbox ohne Zugriff nach außen.
Ersetze doch mal das #define durch #define FILE_PATH [NSHomeDirectory() stringByAppendingPathComponent:mad:"Documents/ownText.txt"].

In den Documents-Folder darfst Du reinschreiben.