I have created an app with a UISearchbar and a UITableView inside a UIPopoverController. Whenever I perform a search, the table correctly shows the right position needed, but when i dismiss the popover , automatically the current position and the selected cell is lost.
So the situation is, I need when the popover is dismissed, and then re-called, to show me the exact position before the dismissal. My guesses are, when the popover is dismissed, the uitableview gets reloaded to starting position.
N.B. : The problem occurs when I perform the search using the search bar and dismiss the popover, If I don't use the search bar and just scroll down the table view, click on an item , dismiss the popover, and then re-open it, I will get the exact position I left it before dismissal.
This small sketch could help out more :
Any ideas what I may be doing wrong ?
2 Answers
For what I understand you're are saving UITableview position when you dismiss de popover and reloading it when the popover is called. If you perform a search the position of the UITableview change so if you save that position, when the popover reloads it will go to a different place because the search wasn't performed.
What I think you should is. Save the search before you dismiss the popover. In viewDidLoad perform the search and then use the saved position of the UITableview to scroll to the right position.
The solution was that i needed to create a new mutable array that saves the newly filtered data. If the user searches an item, a boolean variable will change its value. In the view will appear method, a test on that boolean value will take place : If it had changed, the app will load the newly created mutable array, if not it will load the usual array. Hope this would help someone in the future.