I have trouble by doing a sort of concatenation;
I receive 4 different datas that I get with “[dico objectForKey:@”alertSerie”]” (for example).
The datas must be shown with a String that introduce datas on the screen.
I have to put those datas in one UITextField.
Example :
[dico objectForKey:@"alertfriend"] = Beth
[dico objectForKey:@"alertmom"] = Lise
[dico objectForKey:@"alertgirlf"] = Angela
text for Beth will be "This is my friend :"
text for Lise will be "This is my mom :"
text for Angela will be "This is my girlfriend :"
and in the UITextField, I want to show:
This is my friend :Beth
This is my mom : Lise
This is my girlfriend : Angela
Until now it’s OK, the code looks like :
field.text = [NSString stringWithFormat:@"NThis is my friend : %@\nTHis is my mom : %@\nThis is my girlfriend : %@\n",[dico objectForKey:@"alertfriend"], [dico objectForKey:@"alertmom"], [dico objectForKey:@"alertgfriend"] ];
Now, it could be possible that one person have no friend or no mom or no girlfriend…
How can I do???
I tried a lot of possibilities but the fact that we cannot concatenate object isn’t usual for me and it cause me a problem in this situation…
Thanks a lot for your attention!!!
EDIT:
I tried that code but there are mistakes of ; ] or something else…
if ([dico objectForKey:@"alertSerie"]) {
NSString *serie = [NSString stringWithFormat:@"Numéro de série : %@\n", [dico objectForKey:@"alertSerie"] ];}
else {
NSString *serie = [NSString stringWithFormat:@" "] ];}
if ([dico objectForKey:@"alertDate"]) {
NSString *date = [NSString stringWithFormat:@"Date de mise en service : %@\n", [dico objectForKey:@"alertDate"] ];}
else {
NSString *date = [[NSString stringWithFormat:@" "] ];}
if ([dico objectForKey:@"alertCli"]) {
NSString *cli = [NSString stringWithFormat:@"Nom du client associé : %@\n", [dico objectForKey:@"alertCli"] ];}
else {
NSString *cli = [NSString stringWithFormat:@" "] ];}
You need to check wether the person has a friend, girlfriend and mom. This means that you must use conditions. This could be done by using some simple if-statements.