Objective c 无法将对象添加到NSMutableArray数组

Objective c 无法将对象添加到NSMutableArray数组,objective-c,nsmutablearray,Objective C,Nsmutablearray,你好,这是我的第一篇帖子,请耐心等待 我试图将objectself.simata添加到数组self.simataList中,但数组中没有对象。对象self.simata不是nil,我没有得到任何错误 我做错了什么?最有可能的是self.simataList为零。尝试NSLogging self.simataList本身,而不是它的计数。在使用该数组之前,是否确实创建了该数组的实例 @interface SimataDetailViewController () @property Simat

你好,这是我的第一篇帖子,请耐心等待

我试图将object
self.simata
添加到数组
self.simataList
中,但数组中没有对象。对象
self.simata
不是
nil
,我没有得到任何错误


我做错了什么?

最有可能的是self.simataList为零。尝试NSLogging self.simataList本身,而不是它的计数。

在使用该数组之前,是否确实创建了该数组的实例

@interface SimataDetailViewController () 

@property Simata *simata;

@property (nonatomic, copy) NSMutableArray *simataList;

@end

@implementation SimataDetailViewController

@synthesize simataDataController=_simataDataController;
@synthesize category=_category;
@synthesize simata=_simata;
@synthesize simataList=_simataList;

#pragma mark - Managing the detail item



- (void) getSimataForCategory: (NSString *) inputCategory {

    unsigned count = [self.simataDataController.masterList2 count];


    while (count--) {

        if ([[[self.simataDataController objectSimataInListAtIndex:count] categoryCode] isEqual:inputCategory]){
            self.simata= [self.simataDataController objectSimataInListAtIndex:count];

            [self.simataList addObject:self.simata];                       
        }

    }

    NSLog(@"count, %u", [self.simataList count]);


}
也可能是你自己。西玛塔为零

编辑

您可以使用默认的init方法创建数组实例:

self.simataList =[NSMutableArray array];

(+1学分作为一个新手写了一篇相当容易理解的文章。)可能的副本和我应该在哪里创建实例;我希望数组的作用域覆盖整个类。创建一个init方法并将其放置在该类中很可能是您的最佳解决方案。看上面…它起作用了。我必须使用以下语句创建一个实例:self.simataList=[NSMutableArray];。谢谢你的帮助!很高兴它起作用了。您可以在Xcode中使用断点并将鼠标悬停在变量上,以检查它们是否已创建。如果您看到一个nil指针(0x0),通常意味着您没有正确启动对象。
-(id)init
{
    self = [super init];
    if(self)
    {
        //do your object initialization here
        self.simataList =[NSMutableArray array];
    }
    return self;
}