无法将对象添加到NSMutableArray数组 [英] Cannot add object to an NSMutableArray array

查看:83
本文介绍了无法将对象添加到NSMutableArray数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

@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]);


}

您好,这是我的第一篇文章,所以请耐心等待.

Hello this is my first post, so please be patient.

我正在尝试将对象self.simata添加到数组self.simataList中,但是该数组保留有零个对象.对象self.simata不是nil,并且我没有收到任何错误.

I am trying to add object self.simata to array self.simataList but the array stays with zero objects. The object self.simata is not nil and I don't get any error.

我在做什么错了?

推荐答案

确定要在使用数组之前创建该数组的实例吗?

Are you sure you have created an instance of the array before you use it?

self.simataList =[NSMutableArray array];

也可能是你的self.simata没了...

It could also be your self.simata being nil...

编辑

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

You could create the array instance in the default init method:

-(id)init
{
    self = [super init];
    if(self)
    {
        //do your object initialization here
        self.simataList =[NSMutableArray array];
    }
    return self;
}

这篇关于无法将对象添加到NSMutableArray数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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