gpt4 book ai didi

objective-c - 调试 'message sent to deallocated instance'

转载 作者:行者123 更新时间:2023-12-03 17:54:54 24 4
gpt4 key购买 nike

好的,所以我再次面临发送到已释放实例的可怕的消息...

  • 我正在使用DMTabBar (基本上是一个类似 Xcode 的 TabBar 控件)
  • ARC 已启用

现在,交易如下:

  • 控件附带的示例运行良好
  • 我已经启用了 Zombies(甚至尝试使用 Instruments 进行调试 - 说实话 - 我不知道要寻找什么)
  • 已释放实例是 TabBar 的 tabBarItems 数组(托管不同按钮的数组)。

这就是我添加项目的方式:

NSMutableArray* sidebarItems = [@[
[DMTabBarItem tabBarItemWithIcon:[NSImage templateImageNamed:@"One" withSize:iconSize] tag:0 tooltip:@"Files"],
[DMTabBarItem tabBarItemWithIcon:[NSImage templateImageNamed:@"Two" withSize:iconSize] tag:1 tooltip:@"Explorer"],
[DMTabBarItem tabBarItemWithIcon:[NSImage templateImageNamed:@"Three" withSize:iconSize] tag:2 tooltip:@"Bookmarks"],
[DMTabBarItem tabBarItemWithIcon:[NSImage templateImageNamed:@"Four" withSize:iconSize] tag:3 tooltip:@"Search"]
] mutableCopy];

[sidebarTabs setTabBarItems:items];

// Handle selection events
[sidebarTabs handleTabBarItemSelection:^(DMTabBarItemSelectionType selectionType, DMTabBarItem *targetTabBarItem, NSUInteger targetTabBarItemIndex) {
if (selectionType == DMTabBarItemSelectionType_WillSelect) {
[sidebarTabView selectTabViewItem:[sidebarTabView.tabViewItems objectAtIndex:targetTabBarItemIndex]];
} else if (selectionType == DMTabBarItemSelectionType_DidSelect) {
}
}];

这是不同元素的声明方式:

@interface myAppl : NSWindowController
{
IBOutlet DMTabBar* sidebarTabs;
IBOutlet NSTabView* sidebarTabView;
}

这是DMTabBar的界面(最“重要”的部分):

@interface DMTabBar : NSView {

}

// set an NSArray of DMTabBarItem elements to populate the DMTabBar
@property (nonatomic,strong) NSArray* tabBarItems;

// change selected item by passing a DMTabBarItem object (ignored if selectedTabBarItem is not contained inside tabBarItems)
@property (nonatomic,assign) DMTabBarItem* selectedTabBarItem;
<小时/>

你能向我解释一下我做错了什么吗?我绝对不是内存管理方面的大师(是的,我承认我还有一些学习要做),但我肯定会因为这个而自杀......

我正在设置tabBarItems,它们似乎就在那里(至少一开始是这样)。他们为何被释放? (记住控制和项目代码都使用 ARC)。

有什么想法吗? (如果您需要了解其他信息,请告诉我...)

最佳答案

您是否尝试使用通常的内存调试技术来运行,即

  • 乐器与僵尸,以及
  • 在 Xcode 的编辑方案 > 诊断 > 内存管理选项卡中设置各种标志?

关于objective-c - 调试 'message sent to deallocated instance',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15083001/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com