I’m toggling the datasource of an tableview but the indexPath.row throws me an exception [index x beyond bounds]
cell.customLabel.text = [[(_secondTab.selected) ? secondArray : firstArray objectAtIndex:indexPath.row]elementName];
Any idea how to solve this?
The problem is that the index
indexPath.rowis larger than what exists in eithersecondArrayorfirstArray. To fix the root cause, you need to figure out why the element is missing from your arrays. To ensure it doesn’t crash and simply loads an empty string in the label’s text property, check that the largest index in the array is greater than or equal toindexPath.row: