I have a 2D array of string and i am trying to pass the array into a table however i get the error
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM isEqualToString:]: unrecognized selector sent to instance 0x17045d8b0'
I have 3 tables and two of them depend on each other in order to populate a table. So say a user selects an item in table A, then table B should be populated based on table A's input. Table A contains categories and table B contain subcategories of a category selected.
For category i have a one dimensional array and for subCategories i have a 2D array.
My question is how do i access that 2D array such that when a user clicks a category in category table, i can pass that indexPath.row value to the next table which is the subcategory table with a 2D array. So that i get the relevant subCategories.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if (tableView == _queryTypeTableView) {
_contentArray = [_queryTypeCv mutableCopy];
}
else if (tableView == _categoriesTableView){
_contentArray = [_categoryCv mutableCopy];
}
else if (tableView == _subCategoriesTableView){
_contentArray = [_subcategoryCv mutableCopy];
}
return [self.contentArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *simpleTableIdentifier = @"SimpleTableItem";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
if ([tableView isEqual:_queryTypeTableView]) {
cell.textLabel.text = [self.queryTypeCv objectAtIndex:indexPath.row] ;
}
else if ([tableView isEqual:_categoriesTableView]){
cell.textLabel.text = [self.categoryCv objectAtIndex:indexPath.row] ;
_selectedCategoryIndex = (int)indexPath.row;
}
else if ([tableView isEqual:_subCategoriesTableView]){
cell.textLabel.text = [[self.subcategoryCv objectAtIndex:_selectedSubCategoryIndex] objectAtIndex:indexPath.row] ;
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
if ([tableView isEqual:_queryTypeTableView]) {
UITableViewCell *cell = [_queryTypeTableView cellForRowAtIndexPath:indexPath];
[_queryTypeButton setTitle:cell.textLabel.text forState:UIControlStateNormal];
_queryTypeTableView.hidden = YES;
_categoriesButton.enabled = YES;
_categoriesButton.backgroundColor = [UIColor darkGrayColor];
NSLog(@"You selected 1------> %ld!",(long)indexPath.row);
}
else if ([tableView isEqual:_categoriesTableView]){
UITableViewCell *cell = [_categoriesTableView cellForRowAtIndexPath:indexPath];
[_categoriesButton setTitle:cell.textLabel.text forState:UIControlStateNormal];
_categoriesTableView.hidden = YES;
_subCategoriesButton.enabled = YES;
_subCategoriesButton.backgroundColor = [UIColor darkGrayColor];
NSLog(@"You selected 2------> %ld!",(long)indexPath.row);
_categorySelectedFlag = YES;
}
else if ([tableView isEqual:_subCategoriesTableView]){
UITableViewCell *cell = [_subCategoriesTableView cellForRowAtIndexPath:indexPath];
[_subCategoriesButton setTitle:cell.textLabel.text forState:UIControlStateNormal];
_subCategoriesTableView.hidden = YES;
_outcomeButton.enabled = YES;
_outcomeButton.backgroundColor = [UIColor darkGrayColor];
NSLog(@"You selected 3------> %ld!",(long)indexPath.row);
}
}
The error is thrown on this line of code:
cell.textLabel.text = [[self.subcategoryCv objectAtIndex:_selectedSubCategoryIndex] objectAtIndex:indexPath.row] ;