-1

我在我的应用程序 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");
    }


}

多谢,

4

2 回答 2

2

回复:内存管理,这肯定是错误的:

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

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

[self.navPopover release]; 
self.navPopover = nil; 
于 2012-09-10T12:40:33.860 回答
1

你有 DidDismissPopover 吗?

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

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

啊,不要在这里发布

 [self.navPopover release];
 NSLog(@"sconda");
于 2012-09-10T10:17:12.230 回答