Actually .. I have a little different approach to implement this. Instead of an enum you can directly use a dictionary . This is how you can do it
In you .h you can do this..
#define getDictionaryarray() @[ \
@{ \
@"Name": @"John", \
@"ID":@"0" \
}, \
@{ \
@"Name": @"Jerry", \
@"ID":@"1" \
}, \
@{ \
@"Name": @"Jack", \
@"ID":@"2" \
}, \
@{ \
@"Name": @"Jeff", \
@"ID":@"3" \
}, \
@{ \
@"Name": @"Jonny", \
@"ID":@"4" \
}, \
];
Then the table view datasource methods follow
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSArray *array = getDictionaryarray();
return array.count;
}
and in -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
NSArray *dictionaryarray = getDictionaryarray();
cell.textLabel.text = [[dictionaryarray objectAtIndex:indexPath.row] valueForKey:@"Name"];
this would give you a couple of advantages like the id's need not be in the form 0,1,2,3 it can be any number. You can add more attributes to the dictionary like surname etc. And above all it does what you wanted to do :)
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSArray *array = getDictionaryarray();
NSLog(@"Id for selected Name %@ is %@",[[array objectAtIndex:indexPath.row] valueForKey:@"Name"],[[array objectAtIndex:indexPath.row] valueForKey:@"ID"]);
}
Hope this helps...