【发布时间】:2011-11-09 05:06:57
【问题描述】:
我正在做一个项目,其中我正在从异步连接加载带有 JSON 数据的表视图。我正在使用switch 语句来加载每一行,如下所示:
dictionaryData = [responseString JSONValue];
switch (indexPath.row)
{
case 0:
{
NSString *name = [NSString stringWithFormat:@"%@ : %@ %@",@"Name",[dictionaryData valueForKey:@"firstName"],[dictionaryData valueForKey:@"lastName"]];
cell.textLabel.text = name;
break;
}
case 1:
{
NSString *email = [NSString stringWithFormat:@"%@ : %@",@"Email",[dictionaryData valueForKey:@"email"]];
cell.textLabel.text = email; }
break;
有 8 行,我必须编写 8 个 switch case,我认为这使我的方法太长了。 谁能告诉我是否有任何替代 switch 语句的方法。
【问题讨论】:
标签: objective-c ios cocoa-touch uitableview switch-statement