使用多个JSON对象设置单元格的文本 [英] Setting a cell's text with multiple JSON objects
问题描述
这是我目前拥有的代码:
我已经有一个简单的web服务将一些数据传递到表格视图, p> [[cell detailTextLabel] setText:[item objectForKey:@Ball 1]];
正如我所说,这完美地工作,并显示一个球数,例如。 1,取自网络服务。
我想要做的是显示,例如。 1& 3。
查看其他代码我认为可能是:
[[cell detailTextLabel] setText:[item objectForKey:@Ball 1] item objectForKey:@Ball 2]];
我完全是Objective-C的新手,我做了几个教程,试图扩展他们一点。
使用字符串来解决问题有些困难,因为我不确定这些术语。连接,例如 stringWithFormat
:
NSString * concated = [NSString stringWithFormat: @%@&%@,[item objectForKey:@Ball 1],[item objectForKey:@Ball 3]];
现在将此字符串设置为label:
[[cell detailTextLabel] setText:concated];
I've got a simple web service in passing through some data into a table view and it's working fine.
This is the code I currently have:
[[cell detailTextLabel] setText:[item objectForKey:@"Ball 1"]];
As I said, this works perfectly and displays with a ball number, e.g. "1", taken from the web service.
What I want to do is have it display, e.g. "1 & 3".
Looking at some other code I thought it might have been:
[[cell detailTextLabel] setText:[item objectForKey:@"Ball 1"]item objectForKey:@"Ball 2"]];
I'm totally new to Objective-C, and I'm doing a few tutorials and I'm trying to expand on them a bit. It's been a bit difficult to search for answers on some of the stuff because I'm unsure of the terminology.
Use string concatenation, e.g stringWithFormat
:
NSString *concated = [NSString stringWithFormat:@"%@ & %@", [item objectForKey:@"Ball 1"], [item objectForKey:@"Ball 3"]];
and now set this string to label:
[[cell detailTextLabel] setText:concated];
这篇关于使用多个JSON对象设置单元格的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!