ios popover [UIPopoverController]崩溃

时间:2012-09-10 09:53:48

标签: ios memory-management uipopovercontroller

我在我的应用程序WEPopoverController中显示一个弹出窗口,

在用户点击按钮后出现并消失,

有时候工作正常, 但有时它会崩溃,就像我打开i并关闭它很多次它会崩溃,所以我不知道在这个对象的内存管理中缺少什么,

- (void)showPopOver 
{

    if(!self.navPopover) {
          CGRect frame ;
        frame = CGRectMake(0, 0, 270, 132);

        UIViewController *viewCon = [[UIViewController alloc] init];

         viewCon.contentSizeForViewInPopover = frame.size;

        self.navPopover = [[WEPopoverController alloc] initWithContentViewController: viewCon];

        [self.navPopover setDelegate:self];

    } 

    if([self.navPopover isPopoverVisible]) {
        [self.navPopover dismissPopoverAnimated:YES];
        [self.navPopover setDelegate:nil];
        //[self.navPopover autorelease];
        self.navPopover = nil;

        [self.navPopover release];

        //[_navPopover release];
         NSLog(@"sconda");
    } else if (![self.navPopover isPopoverVisible]){



        [self.navPopover presentPopoverFromRect:CGRectMake(134,440, 50, 96)


                                         inView:self.view
                       permittedArrowDirections: UIPopoverArrowDirectionDown

        animated:YES];

        NSLog(@"tanga");
    }


}

非常感谢,

2 个答案:

答案 0 :(得分:2)

重新:内存管理,这肯定是错误的:

self.navPopover = nil; 
[self.navPopover release]; 

通过指向指针,您不会释放该对象。颠倒这些代码行的顺序

[self.navPopover release]; 
self.navPopover = nil; 

答案 1 :(得分:1)

你有DidDismissPopover吗?

 - (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController {
self.navPopover = nil;
} 

你应该以这种方式解雇,而不是在showPopover

上贬低

啊,不要在这里发布

 [self.navPopover release];
 NSLog(@"sconda");