问题描述
我在视图控制器.h文件中声明了NSMutableArray *categories
,并为其声明了一个属性.
I have declared an NSMutableArray *categories
in my view controller .h file, and declared a property for it.
在我的.m文件中NSXMLParser
委托的parser:foundCharacters:
方法中,我有以下代码:
In the parser:foundCharacters:
method of the NSXMLParser
delegate in my .m file, I have this code:
-(void)parser:(NSXMLParser *) parser foundCharacters:(NSString *)string
{
if (elementFound)
{
element = string;
[self.categories addObject:element];
}
}
但是在调试模式下进入它后,当我将鼠标悬停在[self.categories addObject:element]
行上时,XCode告诉我大小为0x0,即0个对象.我的XML文件中有3个元素,因此数组中应包含3个项目.
But when I hover over the [self.categories addObject:element]
line after stepping into it in debug mode, XCode tells me the size is 0x0, 0 objects. There are 3 elements in my XML file so 3 items should be in the array.
我遗漏了一些非常明显的东西,我不知道是什么.
I'm missing something really obvious and I can't figure out what.
推荐答案
"0x0"部分是内存地址.具体来说,"nil",这意味着您的可变数组在被调用时不存在.尝试在您的-init方法中创建它:
The "0x0" part is a memory address. Specifically, "nil", which means your mutable array doesn't exist at the time this is being called. Try creating it in your -init method:
categories = [[NSMutableArray alloc] init];
别忘了在您的-dealloc中释放它.
Don't forget to release it in your -dealloc.
这篇关于NSMutableArray addObject不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!