Property ist plötzlich "tot"

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • Property ist plötzlich "tot"

    Hey,

    ich habe folgendes problem.
    Ich habe einen ViewController, dem ich per Segue eine GUID übergebe. Nun der Code des View Controllers:

    1. Init:

    Quellcode

    1. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
    2. {
    3. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    4. if (self) {
    5. projectGuid = [[WWSProjectGuid alloc] init];
    6. }
    7. return self;
    8. }



    2. setProjectGuid (per Segue übergeben):

    Quellcode

    1. -(void)setProjectGuid:(NSString *)guid {
    2. projectGuid.guid = guid;
    3. }



    Bis dahin klappt alles wunderbar.

    Nun das Problem.

    Quellcode

    1. -(IBAction)clickedAddRoom:(id)sender {
    2. [self createNewRoom];
    3. }
    4. -(void)createNewRoom {
    5. WWSRoom *newRoom = [[[WWSRoom alloc] init] autorelease];
    6. [newRoom setName:roomName_textField.text];
    7. [newRoom setGuid:[WWSFunctions stringWithUUID]];
    8. [newRoom setProjectID:projectGuid.guid];
    9. WWSDatabaseController *databaseController = [[WWSDatabaseController alloc] initDatabaseWithName:@"maindatabase.sqlite"];
    10. [databaseController insertNewRoom:room toProjectByGUID:room.projectID];
    11. }
    Alles anzeigen



    in den letzten beiden Methoden oben, ist mein object projectGuid plötzlich Nil (Adresse:0x0000000) und somit "gelöscht".

    aber wieso ?
    Mein Blog: danielbocksteger.wordpress.com

    schaut mal vorbei :)
  • habe sie nun in viewDidLoad initialisiert. Nun geht's :)

    Allerdings ein neues (fast identisches problem.

    .h

    Quellcode

    1. #import <Foundation/Foundation.h>
    2. @interface WWSProjectGuid : NSObject
    3. @property (nonatomic, retain) NSString *guid;
    4. -(NSString *)getGuid;
    5. -(void)setProjectGuid:(NSString *)pGuid;
    6. @end
    Alles anzeigen



    .m

    Quellcode

    1. #import "WWSProjectGuid.h"
    2. @implementation WWSProjectGuid
    3. @synthesize guid;
    4. -(id)init {
    5. if (self) {
    6. guid = [[[NSString alloc] init] autorelease];
    7. }
    8. return self;
    9. }
    10. -(void)setProjectGuid:(NSString *)pGuid {
    11. self.guid = pGuid;
    12. }
    13. -(NSString *)getGuid {
    14. return self.guid;
    15. }
    16. -(void)dealloc {
    17. [self.guid release];
    18. [super dealloc];
    19. }
    20. @end
    Alles anzeigen



    in der Methode setProjectGuid wird der String noch erfolgreich übergeben. Wenn ich allerdings (unmittelbar danach), getGuid aufrufe, ist self.guid leer, Aber noch initialisiert. leer im sinnet von @"" ;)
    Mein Blog: danielbocksteger.wordpress.com

    schaut mal vorbei :)
  • Quellcode

    1. guid = [[[NSString alloc] init] autorelease];
    2. -(void)dealloc {
    3. [self.guid release];
    4. [super dealloc];
    5. }

    Brrrrr, bäh, bäh! ;)

    Du solltest mal ganz, ganz dringend etwas zur Speicherverwaltung lesen.

    Besser

    Quellcode

    1. self.guid = @"";
    2. -(void)dealloc {
    3. self.guid = nil;
    4. [super dealloc];
    5. }
    „Meine Komplikation hatte eine Komplikation.“
  • Keine Veränderungen

    okay, hat nicht wirklich etwas geändert...

    noch mal von vorn:
    Im Viewcontroller wird aufgerufen:

    Quellcode

    1. -(void)setProjectGuid:(NSString *)guid {
    2. if (projectGuid == nil) {
    3. projectGuid = [[WWSProjectGuid alloc] init];
    4. }
    5. [projectGuid setGuid:guid];
    6. }



    code der ProjectGuid-Klasse .h:

    Quellcode

    1. #import <Foundation/Foundation.h>
    2. @interface WWSProjectGuid : NSObject
    3. @property (nonatomic, retain) NSString *guid;
    4. -(NSString *)getGuid;
    5. @end
    Alles anzeigen




    .m

    Quellcode

    1. #import "WWSProjectGuid.h"
    2. @implementation WWSProjectGuid
    3. @synthesize guid;
    4. -(id)init {
    5. if (self) {
    6. self.guid = @"";
    7. }
    8. return self;
    9. }
    10. -(NSString *)getGuid {
    11. return self.guid;
    12. }
    13. -(void)dealloc {
    14. self.guid = nil;
    15. [super dealloc];
    16. }
    17. @end
    Alles anzeigen




    Nun wird im Viewcontroller beim click auf einen Button folgendes aufgerufen:

    Quellcode

    1. -(IBAction)clickedAddRoom:(id)sender {
    2. [self createNewRoom];
    3. }
    4. -(void)createNewRoom {
    5. WWSRoom *newRoom = [[[WWSRoom alloc] init] autorelease];
    6. [newRoom setName:roomName_textField.text];
    7. [newRoom setGuid:[WWSFunctions stringWithUUID]];
    8. [newRoom setProjectID:[projectGuid getGuid]];
    9. WWSDatabaseController *databaseController = [[WWSDatabaseController alloc] initDatabaseWithName:@"maindatabase.sqlite"];
    10. [databaseController insertNewRoom:newRoom toProjectByGUID:newRoom.projectID];
    11. }
    Alles anzeigen



    Das Problem nun, dass Objekt 'guid' in der Klasse ProjectGuid, ist leer, obwohl es in der setProjectGuid-Methode ERFOLGREICH gefüllt wurde.
    Mein Blog: danielbocksteger.wordpress.com

    schaut mal vorbei :)

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von DBocksteger_04 ()