- [__ NSArrayI isEqualToString:]:消息发送到解除分配的实例 [英] -[__NSArrayI isEqualToString:]: message sent to deallocated instance

查看:189
本文介绍了 - [__ NSArrayI isEqualToString:]:消息发送到解除分配的实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



它已经在父视图中收到,因此


我已经将NSArray值传递给父视图。 (NSArray *)arrayValues withIndexPath:(NSIndexPath *)myIndexPath
{
manufacturingSearchObjectString = [arrayValues valueForKey:@ 制造商];
NSLog(@%@,[arrayValues valueForKey:@MANUFACTURER]);
manufacturingResultIndexPath = myIndexPath;
[self.tableView reloadData]; //重新加载表格,以便您可以在tableViewCell中查看该值。
}

如果我要执行此代码并选择子视图的tablecell,执行代理,然后冻结并将该错误触发到日志

  2011-10-31 14:06:16.670 code [ 12610:207](
阿尔法罗密欧

2011-10-31 14:06:16.673 code [12610:207] *** - [__ NSArrayI isEqualToString:]:取消分配的实例0x6859280

但是,如果我在委托方法中注释掉以下行

$ (NSArray *)arrayValues withIndexPath:(NSIndexPath *)myIndexPath
{
// manufacturingSearchObjectString = [arrayValues valueForKey:@MANUFACTURER];
NSLog(@%@,[arrayValues valueForKey:@MANUFACTURER]);
manufacturingResultIndexPath = myIndexPath;
[self.tableView reloadData]; //重新加载表格,以便您可以在tableViewCell中查看该值。
}

它不会崩溃,我最终得到NSLog的正确细节我的日志如此。

  2011-10-31 14:09:28.200 code [12737:207](
索尼

我希望有人曾经遇到过这样的问题,这是我的数组对象看起来像一个数值字典。

  ISELECT = F; 
ISALIVE = T;
制造商=索尼;
MANUFACTURERID = 3;


解决方案

valueForKey:返回一个自动释放的实例。除非你保留它,否则你可以期望在从当前方法返回之后的某个时间被释放。看起来你把它分配给一个实例变量。如果你这样做,你需要保留它。

  manufacturingSearchObjectString = [arrayValues valueForKey:@MANUFACTURER]; 
[manufacturingSearchObjectString retain];

但是看起来你还有另一个问题。

  [arrayValues valueForKey:@MANUFACTURER]; 

返回数组。

  manufacturingSearchObjectString = [arrayValues valueForKey:@MANUFACTURER]; 

通过变量的名称,它看起来好像将其分配给一个字符串变量。所以如果你修复保留问题,那么你会有另一个错误。当您尝试调用isEqualToString时,您将收到一个无法识别的选择器。



您需要为producerSearchObjectString分配一个字符串值。你需要弄清楚你想要的字符串值。在这种情况下,你的数组中只有一个字符串,所以我想你想要一个。在这种情况下

  manufacturingSearchObjectString = [[arrayValues valueForKey:@MANUFACTURER] objectAtIndex:0]; 
[manufacturingSearchObjectString retain];

但是,一般来说,您需要检查数组中是否有多个值,并决定哪个一个你想要的,还要检查数组中是否没有值,并做一些正确的处理。


I have passed an NSArray value back to a parent view using a delegate.

it is received in the parent view like so

- (void) setManufactureSearchFields:(NSArray *)arrayValues withIndexPath:(NSIndexPath *)myIndexPath
{
    manufactureSearchObjectString = [arrayValues valueForKey:@"MANUFACTURER"];
    NSLog(@"%@",[arrayValues valueForKey:@"MANUFACTURER"]);
    manufactureResultIndexPath = myIndexPath;
    [self.tableView reloadData]; //reloads the tabels so you can see the value in the tableViewCell.
}

If i was to execute this code and select the tablecell of the childview it obviously executes the delegate but then freezes up and fires this error to the Log

2011-10-31 14:06:16.670 code[12610:207] (
    "Alfa Romeo"
)
2011-10-31 14:06:16.673 code[12610:207] *** -[__NSArrayI isEqualToString:]: message sent to deallocated instance 0x6859280

However if I comment out the following line in my delegate method

   - (void) setManufactureSearchFields:(NSArray *)arrayValues withIndexPath:(NSIndexPath *)myIndexPath
    {
        //manufactureSearchObjectString = [arrayValues valueForKey:@"MANUFACTURER"];
        NSLog(@"%@",[arrayValues valueForKey:@"MANUFACTURER"]);
        manufactureResultIndexPath = myIndexPath;
        [self.tableView reloadData]; //reloads the tabels so you can see the value in the tableViewCell.
    }

it dose not crash and I end up with the NSLog with the correct details in my log like so.

2011-10-31 14:09:28.200 code[12737:207] (
    Sony
)

I am hoping someone has experianced such a problem before, this is what my array object looks like, its a dictionary of values.

ISELECT = F;
ISALIVE = T;
MANUFACTURER = Sony;
MANUFACTURERID = 3;

解决方案

valueForKey: returns an autoreleased instance. Unless you retain it, you can expect it will be deallocated sometime after you return from the current method. It looks like you are assigning it to an instance variable. If you do that, you need to retain it.

manufactureSearchObjectString = [arrayValues valueForKey:@"MANUFACTURER"];
[manufactureSearchObjectString retain];

But it looks like you have another problem.

[arrayValues valueForKey:@"MANUFACTURER"];

That returns an array.

manufactureSearchObjectString = [arrayValues valueForKey:@"MANUFACTURER"];

By the name of your variable, it looks as though you're assigning it to a string variable. So if you fix the retain issue, then you will have another error. You will get an unrecognized selector when you try to call isEqualToString on it.

You need to assign a string value to manufactureSearchObjectString. You need to figure out what string value you want that to be. In this case you only have one string in your array, so I guess you want that one. In that case

manufactureSearchObjectString = [[arrayValues valueForKey:@"MANUFACTURER"] objectAtIndex:0];
[manufactureSearchObjectString retain];

But in general you need to check if there is more than one value in the array, and decide which one you want, and also check if there are no values in the array, and do something correct to handle that.

这篇关于 - [__ NSArrayI isEqualToString:]:消息发送到解除分配的实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆