I am loading a tableview with the contents from web service using json frameworks in asynchronous connection. The data is in the json object form
{"id":1,"firstName":"A","lastName":"B","email":"abc@yahoo.com","salary": {"monthly":$5000,"annual":$60000}}
I am loading tableview using switch statement in cellForRowAtIndexPath:
dictionaryData = [responseString JSONValue];
switch (indexPath.row)
{
case 0:
cell.textLabel.text = [NSString stringWithFormat:@"%@ : %@ %@",@"Name",[dictionaryData valueForKey:@"firstName"],[dictionaryData valueForKey:@"lastName"]];
break;
case 1:
cell.textLabel.text = [NSString stringWithFormat:@"%@ : %@",@"Email",[dictionaryData valueForKey:@"email"]];
break;
case 2:
cell.textLabel.text = [NSString stringWithFormat:@"%@ : %@",@"Monthly Salary",[[dictionaryData valueForKey:@"salary"]valueForKey:@"monthly"]];;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
break;
case 3:
cell.textLabel.text = [NSString stringWithFormat:@"%@ : %@",@"Annual Salary",[[dictionaryData valueForKey:@"salary"]valueForKey:@"annual"]];
break;
default:
break;
}
This is for normal data, but when i have more fields like phone number, address, department number, etc , then writing too many cases will make the method very large.Can someone help me how i can do this without switch.