我有一个NSMutableArray的叫组织这是I类从NSObject的子类的自定义对象的数组,这个子类被称为NSXOrganisation。这个子类实现NSCopy像这样:与获取和改变NSMutableArray的问题对象
@interface NSXOrganisation : NSObject <NSCopying>
...
- (id)copyWithZone:(NSZone *)zone
{
id copy = [[[self class] alloc] init];
if (copy)
{
[copy setPropertyOne:[[[self getPropertyOne] copyWithZone:zone] autorelease]];
}
return copy;
}
现在,我的Alloc &数组初始化像这样:
organisations = [[NSMutableArray alloc] initWithArray:organisationsArray copyItems:YES];
这一切工作正常。为了测试,阵列中有2个对象。
接着,当方法被调用时,我更新所述阵列中的物体,像这样:
- (void)updateOrganisation
{
[[organisations objectAtIndex:0] setConsumerKey:[tfPropertyOne stringValue]];
}
凡tfPropertyOne *是的NSTextField在显示器上(绑定正确等)。这也工作正常,因为我已经用NSLog测试过,并输出正确的结果。然后我请不同的索引的显示方法在阵列中,以查看其相关的详细信息:
- (void)displayOrganisation:
{
[tfPropertyOne setStringValue:[[organisations objectAtIndex:index] getPropertyOne]];
}
索引是本地NSInteger的并且是没有问题的。然后我对这个对象调用相同的更新方法,这显然工作正常(使用NSLog测试)。
最后,当我打个电话回去,并在阵列显示的第一个对象[自displayOrganisation:0]通话成功的作品,但我的应用程序崩溃调用getPropertyOne时。
这是Mac的控制台错误:
...: Invalid memory access of location 0x3bcfd069 eip=0x90c1cd5c
这是从崩溃报告:
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libobjc.A.dylib 0x90c1cd4b objc_msgSend + 27
1 com.apple.Foundation 0x943da945 _NSDescriptionWithLocaleFunc + 57
2 com.apple.CoreFoundation 0x906503ae __CFStringAppendFormatCore + 12238
3 com.apple.CoreFoundation 0x906a70dc _CFStringCreateWithFormatAndArgumentsAux + 108
4 com.apple.CoreFoundation 0x9072821c _CFLogvEx + 124
5 com.apple.Foundation 0x9445d221 NSLogv + 136
6 com.apple.Foundation 0x9445d194 NSLog + 27
7 co.nz.fdl.XeroConnect 0x1b5b4872 -[PrefsController displayOrganisation:] + 194 (PrefsController.mm:229)
谁能帮助?我是否正确访问/创建/将对象存储到数组中?
我没有在我的代码autorelease调用,所以它不是那么不幸。 – Aleks 2012-07-27 01:08:32