Search code examples
iosiphoneuitableviewuisearchdisplaycontrollerpresentmodalviewcontroller

issue modally presenting a table view controller that has a search display controller and returning the selected cell


in my iOS application, i'm wanting to present the user a table of items using a UITableViewController, have them select an item, then return that item back to the another view controller. i can do this successfully by defining a protocol and delegate method for the table view controller, presenting the table view controller modally, then dismissing it when the user selects an item and returning the item to the delegate view controller. but, if i also implement a search display controller for the table view (so the user can search for a specific item in a longer list) i run into a memory issue. i've modified apple's 'TableSearch' example to demonstrate this, and have posted the code at https://github.com/pistachionut/Table-Search-Example

in short, the app usually crashes with an EXC_BAD_ACCESS just after selecting a cell in the table view. running it with NSZombieEnabled is indicating that the table view controller is being called by -[UISearchDisplayController _destroyManagedTableView] after its retain count has reached 0. anyone have an idea why this is happening? i don't think i'm doing any additional releasing of the table view controller beyond what i'm responsible for. i create it using alloc and initWithNibName, present it modally, then imediately release it (see -(IBAction)showProductPicker:(id)sender in the 'PickProductViewController.m' file in my example). thanks!


Solution

  • the answer posted by Jeff to How can UISearchDisplayController autorelease cause crash in a different view controller? solves the problem.