- 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
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
SaveTextAppDelegate.m
Ich kann meinen Fehler einfach nicht finden!!!
THX im Vorraus!
nachdem ich ausgiebig die SuFu penetriert habe komme ich an dieser stelle nicht mehr weiter... evtl mangelt es am objective c know how
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
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
THX im Vorraus!