Iphone presentPopover-EXC\u坏访问;使用僵尸对象
我正试图让Iphone presentPopover-EXC\u坏访问;使用僵尸对象,iphone,objective-c,ios,ipad,exc-bad-access,Iphone,Objective C,Ios,Ipad,Exc Bad Access,我正试图让presentPopoverFromRect工作,但由于内存访问不好,我一直遇到崩溃(EXC\u坏访问) 下面是代码,最后一行是它崩溃的地方: - (void)showChat:(id)sender { chat = [[PopupChatController alloc] initWithStyle:UITableViewStylePlain]; chat.chatDelegate = self; self.chatPopover = [[UIPopoverController
presentPopoverFromRect
工作,但由于内存访问不好,我一直遇到崩溃<代码>(EXC\u坏访问)
下面是代码,最后一行是它崩溃的地方:
- (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
的保留计数:
例如
它们都很好(>0)。所以我对这里发生的事完全困惑不解
如果有人能帮忙,我将非常感激
另外,我在XCode中启用了Zombie对象(产品>编辑方案>诊断>启用Zombie对象),但在控制台中没有任何Zombie变量的输出。也许我找错地方了
如果您对此有任何建议,我们也将不胜感激
提前谢谢 变量chat的内存泄漏 尝试以下代码,并将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];
}顺便问一下,您是否将属性chatPopover定义为retain?带弧还是不带弧。。。什么时候发生坠机?chatDelegate和chatPopover是如何声明的?(强,弱…)您是否在Objective-C异常上设置了断点?如果没有,尝试一下……它可能会给出比“EXC\u BAD\u ACCESS”更好的错误消息。该功能在按下UIButton时调用。chatDelegate为(非原子,保留)而chatPopover为(非原子,保留)。。。“我不确定这是否回答了这个问题?”菲利普米尔斯感谢你的帮助。我确实添加了一个断点,它使我能够跟踪错误,这实际上是在窗口本身,而不是我在这里发布的代码中。令人沮丧的!!!!!不过谢谢你的帮助。retainCount永远不会返回零。
- (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];