2016-06-29 5 views
-2

JSONからコレクションビューのセルのラベルにデータを取得しようとしています。私は同じラベルの中に名前と年齢を表示する必要があります。JSONを介して同じラベルに名前と年齢を表示

enter image description here

私はすでにデータを取得していますが、4つすべてのラベルを別々に取っています。どのように私は2つの異なるラベルで同じことをすることができます。

+2

使用stringWithFormatのように ' [NSString stringWithFormat:@ "%@(%@)"、@ "dave123"、@ "50"] ' –

+0

本当ですか? '[NSString stringWithFormat:]'の使い方に関する質問? – Droppy

+0

誰もがどこかの人たちを始めなければならない.. – emotality

答えて

0

あなたが行うことができ、以下による:

self.LabelName.text=[NSString stringWithFormat:@"%@ , %@",name,age]; 
+0

名前と年齢はjson @priya sharmaから解析したものです – Muthukumar

0
NSDictionary *json = @{@"name":@"dave123", @"age":@"50"}; 
NSString *name = json[@"name"]; 
NSString *age = json[@"age"]; 

UILabel *nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 64, 320, 40)]; 
[nameLabel setText:[NSString stringWithFormat:@"%@ (%@)", name, age]]; 
[self.view addSubview:nameLabel]; 
0

あなたはstringWithFormat使用することができます。

str1 = @"test1"; 
str2 = @"test2"; 
yourLabel = [NSString stringWithFormat:@"str1:%@ and str2:%@", str1, str2]; 

yourLabel - > STR1:TEST1とstr2:TEST2

関連する問題