Reputation:
I am New at iPhone Development.
I have Dictionary of Array.
{
A = (
{
address = "Talala (gir)";
"main_id" = 1;
mobile = 8878876884;
name = "Amit Patel";
},
{
address = "Junagdh";
"main_id" = 5;
mobile = 4894679865;
name = "Arjun Patel";
}
);
J = (
{
address = "Taveli";
"main_id" = 6;
mobile = 87886356085878;
name = "Jasmin Patel";
},
{
address = "Gujarat";
"main_id" = 4;
mobile = 6636633368;
name = "Jatin ";
}
);
R = (
{
address = "Mumbai";
"main_id" = 2;
mobile = 999686322;
name = "Rajan Patel";
}
);
S = (
{
address = "Rajkot";
"main_id" = 3;
mobile = 8866086549;
name = "Sumit Patel";
}
);
}
I have UITableView
and i want to display value which has key "name"
on UITableViewCell
My cellForRowAtIndexPath
method is
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = [[[self.finalPDic objectForKey:[self.listOfHeader objectAtIndex:indexPath.row]] objectAtIndex:indexPath.row] objectForKey:@"name"];
return cell;
}
But above code is crush not work for me.
Upvotes: 0
Views: 128
Reputation: 9346
There are quite some issues with this code ...
The first indexPath.row has to be indexPath.section.
As a general hint, it would be better to organize your code more readable, like:
NSArray* nameArrayForLetter = [self.finalPDic objectForKey:[self.listOfHeader objectAtIndex:indexPath.section];
NSDictionary* addressDict = [nameArrayForLetter objectAtIndex:indexPath.row];
NSString* nameString = [addressDict objectForKey:@"name"];
Upvotes: 1
Reputation: 530
Your code iterates through the root keys one by one, but you wont start by index 0 in the lower levels. (the S key is the 4th, so you want the 3rd item it that array, which doesnt exists.
try using sections. A..S is the section and the rows are the names!
Upvotes: 0