0

我正在尝试开始presentPopoverFromRect工作,但由于内存访问错误,我一直在崩溃。(EXC_BAD_ACCESS).

这是代码,最后一行是它崩溃的地方:

- (void)showChat:(id)sender {

chat = [[PopupChatController alloc] initWithStyle:UITableViewStylePlain];

chat.chatDelegate = self;

self.chatPopover = [[UIPopoverController alloc] initWithContentViewController:chat];

CGRect myRect = CGRectMake(50, 0, 225, 25) ;

[self.chatPopover presentPopoverFromRect:myRect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

}

使用 gdb 我检查了self.view和的保留计数self.chatPopover

例如。

p (int)[self.view retainCount]

他们都很好(> 0)。所以我完全不知道这里发生了什么?

如果有人可以提供帮助,我将不胜感激。

另外,顺便说一句,我在 XCode 中启用了 Zombie Objects (Product > Edit scheme > Diagnostics > Enable Zombie Objects),但我没有在控制台中的任何僵尸变量上获得任何输出。也许我找错地方了?

对此的任何建议也将不胜感激。

提前致谢。

4

2 回答 2

0

变量chat存在内存泄漏。

尝试以下代码并将聊天设置为局部变量。

- (void)showChat:(id)sender {

  PopupChatController *chat = [[PopupChatController alloc]    initWithStyle:UITableViewStylePlain];

  chat.chatDelegate = self;

  self.chatPopover = [[UIPopoverController alloc] initWithContentViewController:chat];

  [chat release]; //since it's retained in the UIPopoverController

  CGRect myRect = CGRectMake(50, 0, 225, 25) ;

  [self.chatPopover presentPopoverFromRect:myRect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

}

于 2012-11-22T01:19:06.990 回答
0

顺便说一句,您是否将属性 chatPopover 定义为保留?

于 2012-11-22T01:22:14.567 回答