gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-30 04:02:23 25 4
gpt4 key购买 nike

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


}

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

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

我做错了什么?

最佳答案

您确定在使用数组之前已经创建了一个实例吗?

self.simataList =[NSMutableArray array];

也可能是你的 self.simata 为 nil...

编辑

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

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

关于objective-c - 无法将对象添加到 NSMutableArray 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9658679/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com