Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Your problem is totally logical and does not need a change in your code. When you sort the <code>tableView</code> array, it is trivial that <code>didSelectRowAtIndexPath</code> would get messed up while selecting rows.</p> <p>This might be because you would have implemented something like</p> <pre><code>- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.section == 0) { if (indexPath.row ==0) // PushViewController to view 1 // if (indexPath.row ==1) // PushViewController to view 2 // } if (indexPath.section ==1) // Do something like before </code></pre> <p>If this is your case, then yes, when your sort the tableView you will push view controllers in a BAD WAY.</p> <p>My suggestion is that you can take some properties in each row and check for that while pushing view controllers. For example, if you are... (say) having row 1 to be a certain letter or a number or a word, you can check for that and pushViewController accordingly.</p> <p>But this will work only if you know all the elements in the <code>tableView</code> (never mind sorting).</p> <p>You can check something like...</p> <pre><code>- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath]; if (selectedCell.textLabel.text = @"1") // push view controller to view 1 if (selectedCell.textLabel.text isEqualToString: self.lifeStyle) // push view controller to lifeStyleViewController // here lifeStyle is a NSString property // </code></pre> <p>You can check for anything if you logically set and assign your properties in the <code>cellForRowAtIndexPath</code> method and logically set it such that when you perform a <code>tableView reloadData</code> after sorting, the flow of the <code>didSelect</code> would still be the same.</p> <p>Let us know if you still have problems. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload