robobooga
robobooga

Reputation: 513

Xcode Reading NSDictionary / Table Sections

I have a tableView of 2 Dictionary objects with no problems

[tableData addObject:dictionary1];
[tableData addObject:dictionary2];

The problem lies in where the user clicks a row in for example the first dictionary.

for now, I have been using this :

NSLog(@"You Have Selected: %@", [tableData objectAtIndex:indexPath.row]);

and no matter if i click the first row in either second dictionary or the first one, It still gives me row 1.

How do I identify whether the user clicked the first row in the first one or the second one

EDIT

I use 2 Dictionaries to implement sections within the tableview. If this is causing the problem, may I ask for a similar method to show sections without dictionaries

Upvotes: 0

Views: 823

Answers (2)

Jake
Jake

Reputation: 3973

As James Bedford briefly describes; use indexPath.section to get your section. So if the rows are in a dictionary, and the dictionary is your section with rows, the code should be something like:

NSDictionary *rows = [tableData objectAtIndex:indexPath.section];
id row = [rows objectForKey:[NSString stringWithFormat:@"%d", indexPath.row]];

The code is merely an example. Don't use it, it is not based on best practices :-)

P.S: I assumed you used the row numbers as keys..

Upvotes: 2

James Bedford
James Bedford

Reputation: 28972

Try looking at indexPath.section.

Upvotes: 2

Related Questions