NString value of custom object gets lost after segue (Objective C)

Hadjimina

Heyo Guys

So I am more or less new to Objective C and got to a problem which I seem unable to solve.

I created a class called "Students" which all have a name surname etc. All those Students are put into a NSMutableArray (before they get created from JSON , that seems to work without a problem though). Then all the names of the students are put into a ListView. Afterwards when a name is clicked (segue passes the object), one should see the details of said student (i.e. his full name, his id, his street). The problem is that all the string values of the student object seem to get lost. I checked that all the student object work just fine. I think the problem lies at the @property in my student class.

Any comments and suggestions are appreciated

This is an excerpt of student.h As said only the string values get lost, the int (here the plz value) remains correct

@property (nonatomic, weak)NSString *lastname;
@property (nonatomic, weak)NSString *surname;
@property (nonatomic, weak)NSString *street;
@property (nonatomic, assign)int plz;

EDIT: Here is where i parse my json.

for (NSDictionary *dic in jsonArray){

        NSNumber *identity = [dic valueForKey:@"id"] ;
        NSString *firstName = (NSString*) [dic valueForKey:@"first_name"];
        NSString *lastName = (NSString*) [dic valueForKey:@"last_name"];
        NSString *street = (NSString*) [dic valueForKey:@"street"];
        NSNumber *plz = [dic valueForKey:@"plz"] ;
        NSString *birth = (NSString*) [dic valueForKey:@"date_of_birth"];
        NSArray *bills = dic[@"bills"];
        NSArray *hours = dic[@"hours"];

        NSLog(@"First %@",firstName);



        Student *student = [[Student alloc]initWithLastName:lastName withSurname:firstName withStreet:street withPLZ:plz withOrt:@"Uitikon" withBirthDate:birth withOccupation:@"Schüler"];

        [ApprenticeList addObject:student];
    }

EDIT 2 :

I found out that the string values get lost even before the segue. All these objects are created in

ViewDidLoad

But in

prepareforsegue

all the values are allready null (except for the int) .So the only place where the student objects work is in

ViewdidLoad
Adeel Ahmad
@property (nonatomic, weak)NSString *lastname;
@property (nonatomic, weak)NSString *surname;
@property (nonatomic, weak)NSString *street;

change to

@property (nonatomic, strong)NSString *lastname;
@property (nonatomic, strong)NSString *surname;
@property (nonatomic, strong)NSString *street;

You can also use 'copy'. It will cause the setter for that property to create a copy of the object, otherwise it is identical to strong.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

AngularJS ng-model value is lost after custom validation directive is triggered

From Dev

Value of loop variable after "for in" loop in Objective C

From Dev

JQuery set text value is lost after postback

From Dev

How to store a custom object to user defaults in objective c?

From Dev

AngularJS Select Value Being Lost After Call to Restful Service and Scope Object Update

From Dev

typecasting to custom object - is data lost?

From Dev

How an angular object gets the value of another object

From Dev

Swift / Objective C: How to get value from object by string name

From Dev

Objective C - Lost with retain cycles

From Dev

javascript variable value lost when outside object

From Dev

Segue from Swift to Objective-C

From Dev

Objective C : Custom class in identity inspector creates a new object of that class?

From Dev

How to create segue in Objective c programmatically?

From Dev

Title attribute with value more than 512 character gets lost

From Dev

Custom keymapping is lost after rebooting

From Dev

Objective C: Back button segue not working

From Dev

Performing Segue After Sharing - Objective-C (Xcode)

From Dev

Segue from objective c to swift

From Dev

Is there a way to name an object based on the value of an integer? Objective C

From Dev

Pass data forward by Segue (objective-c)

From Dev

Objective C : Custom class in identity inspector creates a new object of that class?

From Dev

'&' in a classname of objective c gets replaced by '_'

From Dev

Deserialize JSON using Objective-C into a custom object

From Dev

Objective c object initializaiton

From Dev

float type Buffer contents lost after creating object C++

From Dev

Set value to a class object which is property of another class - Objective c

From Dev

string value is lost after encryption

From Dev

Objective-C object are not destroyed after release message

From Dev

Object being lost after post on .net core

Related Related

  1. 1

    AngularJS ng-model value is lost after custom validation directive is triggered

  2. 2

    Value of loop variable after "for in" loop in Objective C

  3. 3

    JQuery set text value is lost after postback

  4. 4

    How to store a custom object to user defaults in objective c?

  5. 5

    AngularJS Select Value Being Lost After Call to Restful Service and Scope Object Update

  6. 6

    typecasting to custom object - is data lost?

  7. 7

    How an angular object gets the value of another object

  8. 8

    Swift / Objective C: How to get value from object by string name

  9. 9

    Objective C - Lost with retain cycles

  10. 10

    javascript variable value lost when outside object

  11. 11

    Segue from Swift to Objective-C

  12. 12

    Objective C : Custom class in identity inspector creates a new object of that class?

  13. 13

    How to create segue in Objective c programmatically?

  14. 14

    Title attribute with value more than 512 character gets lost

  15. 15

    Custom keymapping is lost after rebooting

  16. 16

    Objective C: Back button segue not working

  17. 17

    Performing Segue After Sharing - Objective-C (Xcode)

  18. 18

    Segue from objective c to swift

  19. 19

    Is there a way to name an object based on the value of an integer? Objective C

  20. 20

    Pass data forward by Segue (objective-c)

  21. 21

    Objective C : Custom class in identity inspector creates a new object of that class?

  22. 22

    '&' in a classname of objective c gets replaced by '_'

  23. 23

    Deserialize JSON using Objective-C into a custom object

  24. 24

    Objective c object initializaiton

  25. 25

    float type Buffer contents lost after creating object C++

  26. 26

    Set value to a class object which is property of another class - Objective c

  27. 27

    string value is lost after encryption

  28. 28

    Objective-C object are not destroyed after release message

  29. 29

    Object being lost after post on .net core

HotTag

Archive