saturngod
saturngod

Reputation: 24967

reached while popover is still visible

-(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.

Upvotes: 6

Views: 11449

Answers (3)

Chris
Chris

Reputation: 40613

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.

Upvotes: 6

Dan Rosenstark
Dan Rosenstark

Reputation: 69757

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.

Upvotes: 3

Aaron Saunders
Aaron Saunders

Reputation: 33335

think autorelease is incorrect, here is a tutorial

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

Upvotes: 3

Related Questions