简体   繁体   中英

only 1 of 2 values displayed on UILabel

I want the ServingSize UIlabel on my app to display portion and unit (as in 1 fl. oz.). However, it only displays the unit (so I just see fl. oz.). I don't see what could be going wrong. Below is the relevant code. I declare both portion and unit as NSString* at the top of the .m file. When I NSLog portion after it is assigned, I see the correct value.

for(NSDictionary *dict in self.team){
        portion = [dict objectForKey:@"portion"];
        unit = [dict objectForKey:@"unit"];
    }

    self.ServingSize.text = (@"%@ %@", portion, unit);
    self.Servings.backgroundColor = [UIColor whiteColor];

Use below Code ( I posted this answer because it may be helpfull to other)

or(NSDictionary *dict in self.team){
        portion = [dict objectForKey:@"portion"];
        unit = [dict objectForKey:@"unit"];
    }

    self.ServingSize.text =[NSString stringWithFormat:@"%@ %@", portion, unit];
    self.Servings.backgroundColor = [UIColor whiteColor];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM