6
-(void)showsearch:(id)sender
{
    SearchViewController *searchview =[[SearchViewController alloc] initWithNibName:@"SearchViewController" bundle:nil];

    settingpopoverController = [[[UIPopoverController alloc] 
                                    initWithContentViewController:searchview] autorelease];               
    [searchview release];
    [settingpopoverController presentPopoverFromBarButtonItem:sender 
                                    permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];


}

When I click on button, the app is crash and I got [UIPopoverController dealloc] reached while popover is still visible. message.

jer
  • 20,094
  • 5
  • 45
  • 69
saturngod
  • 24,649
  • 17
  • 62
  • 87
  • you seem to be mixing up *view* and *controller*. is SearchViewController a controller, but you call it a view. – Ross Oct 24 '10 at 16:13

3 Answers3

6

There are some good discussions on this topic here:

Retain/release pattern for UIPopoverController, UIActionSheet, and modal view controllers?

UIPopoverController and memory management

The gist of it is you need to:

  • assign your autoreleased popover to a retain property
  • set the property to nil in your view's dealloc
  • as well as setting it to nil in the popoverControllerDidDismissPopover.
Community
  • 1
  • 1
Chris
  • 39,719
  • 45
  • 189
  • 235
3

think autorelease is incorrect, here is a tutorial

http://www.jannisnikoy.nl/index.php/2010/04/ipad-tutorial-creating-a-popoverviewcontroller

Aaron Saunders
  • 33,180
  • 5
  • 60
  • 80
3

Problem is you're setting

settingpopoverController =

when you mean to do

self.settingpopoverController =

for which the autorelease would be correct. The second one uses the property accessors, the first just uses the iVar.

Dan Rosenstark
  • 68,471
  • 58
  • 283
  • 421
  • @Sanjit Saluja, in Obj-c 2.0 and beyond, the second syntax -- assuming it's a "retain" property -- would call "retain" on the `UIPopoverController` that the OP calls autorelease on. Otherwise when the current method ends, the `UIPopoverController` is autoreleased, reaches a retain count of 0, and is dealloc'ed. Let me know if you think I'm missing something. – Dan Rosenstark Apr 30 '11 at 06:41