HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – 在我的应用程序中找到了一个N​​SZombie …现在怎样?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个NsmanagedObject的子类,有一些“整数32”属性,真的是枚举.这些枚举在我的模型的.h文件中定义,如下所示:

typedef enum {
    AMOwningCompanyACME,AMOwningCompanyABC,AMOwningCompanyOther
} AMOwningCompany;

我需要显示一个表视图,显示自定义对象的每个属性的值,因此对于每个枚举,我有一个看起来像这样方法来返回字符串值:

-(NSArray*)StringsForAMOwningCompany
{
    return [NSArray arrayWithObjects:@"ACME Co.",@"ABC Co.",@"Other",nil];
}

在我的表视图中,我遍历NsmanagedObject的属性(使用NSEntityDescription的attributesByName,对于每个属性,我调用一个调用相应“StringsFor”方法的辅助方法来返回该特定属性的字符串:

-(NSArray*)getStringsArrayForAttribute:(NSString*)attributename
{
    SEL methodSELEctor = NSSELEctorFromString([self methodNameForAttributenamed:attributename]);
    NSInvocation* invocation = [NSInvocation invocationWithMethodSignature:[[AMProperty class] instanceMethodSignatureForSELEctor:methodSELEctor]];
    [invocation setSELEctor:methodSELEctor];
    [invocation setTarget:self.ediTingPole];
    [invocation invoke];

    NSArray* returnValue = nil;
    [invocation getReturnValue:&returnValue];

    return returnValue;
}

我的表视图的cellForRowATindexPath如下所示:

...
NSString* itemname = self.tableData[indexPath.row];
NSAttributeDescription* desc = itemAttributes[itemname];

NSString* cellIdentifier = [self cellIdentifierForAttribute:desc]; // checks the attribute type and returns a different custom cell identifier accordingly
if ([cellIdentifier isEqualToString:@"enumCell"])
{
    // dequeue cell,customize it
    UITableViewCell* enumCell = ...
    ...
    NSArray* stringvalues = [[NSArray alloc] initWithArray:[self getStringArrayForAttribute:itemname]];
    int currentValue = [(NSnumber*)[self.ediTingPole valueForKey:itemname] intValue];
    enumCell.detailTextLabel.text = (NSString*)stringvalues[currentValue];
    return enumCell;
}
...

对于其中一个属性,我一直在NSInvocation的返回数组上崩溃:

-[__NSArrayI release]: message sent to deallocated instance 0x856a4b0

使用Zombies Profiler,我看到:

我正在使用ARC.我该如何进一步调试?

解决方法

我最近遇到了一个非常类似的问题,我花了一段时间才弄明白我做错了什么.这里发布了一个额外的版本 – 因为你的指针returnValue是__strong(认值),ARC认为该对象是通过该指针拥有的,但事实并非如此.

– [NSInvocation getReturnValue:]不取得它的所有权,并且通过指针地址的“赋值”绕过ARC通常使用的objc_storeStrong().

解决方案很简单:将指针标记为__unsafe_unretained.这是事实;该对象不会通过此指针保留(如果它是__strong那样),并且ARC不能在此处释放它.

大佬总结

以上是大佬教程为你收集整理的ios – 在我的应用程序中找到了一个N​​SZombie …现在怎样?全部内容,希望文章能够帮你解决ios – 在我的应用程序中找到了一个N​​SZombie …现在怎样?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。