开发者

Xcode Reading NSDictionary / Table Sections

开发者 https://www.devze.com 2023-02-09 13:27 出处:网络
I have a tableView of 2 Dictionary objects with no problems [tableData addObject:dictionary1]; [tableData addObject:dictionary2];

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


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..


Try looking at indexPath.section.

0

精彩评论

暂无评论...
验证码 换一张
取 消