I have a tableView and I'm tracking which rows were selected by adding the row's indexPath to an array and then adding a checkmark.
I'm iterating through that array using this bit of code in my cellForRowAtIndexPath method and it works like a charm:
for (NSIndexPath * element in indexArray)
if ([indexPath compare:element] == NSOrderedSame) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
However, I'm also taking the value of that row and putting it into another array for other purposes. I figured I could simplify my code if I just used this second array for both cases but I don't understand how I'd rewrite the above code. I get the concept but the above code uses an indexPath comparison and I'll need to compare a string to the array.
It's that 'if' line that I don't know how to change.
for (NSString *element in valueArray) {
if ([indexPath compare:element] == NSOrderedSame) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
Thoughts? Thanks.
Edit With More Info
My array contains 400 unique items that will not change. Adding their indexPath to my array and iterating through it to add checkmarks works fine. The reason why I want iterate using the array's string values instead is because I want to add a searchBar to the tableView.
After I add that searchBar, when I do a search, the searchResultsTableView truncates my 400 unique items down to the few that match that search - so we're down to one or a few rows in my searchResultsTableView. Now let's say we select the first row that was returned in the search - my code then adds that row's indexPath to my indexArray to keep track of checkmarks. It would add the index 0,0.
But then when we cancel out of Search mode, the first row 0,0 would be checked in my tableView because we selected 0,0 in searchResultsTableView - even though the row we selected would be way down the list in the full tableView. See where I'm going? So my thought was to track the row's string instead of it's indexPath to alleviate this problem.
More clear?