iOS如何在0索引的数组中添加对象并在tableview单元格中显示?

iOS如何在0索引的数组中添加对象并在tableview单元格中显示?,ios,objective-c,Ios,Objective C,我有一个问题,一个数组有三个主要对象,我想在每个数组的0索引上添加一个对象 这是 在三个部分中,住宅区和商业区,我想在每个部分中添加所有住宅,所有地块和所有商业区,并在每个部分中添加它们的结果,即在每个部分的顶部添加所有住宅,所有地块和所有商业区 - (void) loadFromDictionary:(NSDictionary *)theDictionary{ _parent_id = -1; _type_id = [[theDictionary objectForKey

我有一个问题,一个数组有三个主要对象,我想在每个数组的0索引上添加一个对象

这是

在三个部分中,住宅区和商业区,我想在每个部分中添加所有住宅,所有地块和所有商业区,并在每个部分中添加它们的结果,即在每个部分的顶部添加所有住宅,所有地块和所有商业区

   - (void) loadFromDictionary:(NSDictionary *)theDictionary{
    _parent_id = -1;
    _type_id = [[theDictionary objectForKey:@"type_id"] intValue];
    _title = [[NSString alloc] initWithString:[theDictionary objectForKey:@"title"]];
    _title_alt1 = [[NSString alloc] initWithString:[theDictionary objectForKey:@"title_alt1"]];
    _title_alt2 = [[NSString alloc] initWithString:[theDictionary objectForKey:@"title_alt2"]];

    if([theDictionary objectForKey:@"parent_id"])
        _parent_id = [[theDictionary objectForKey:@"parent_id"] intValue];

    if([theDictionary objectForKey:@"child_list"])
        _child_list = [[NSMutableArray alloc] initWithArray:[[theDictionary objectForKey:@"child_list"] componentsSeparatedByString:@","]];
}

+ (void)getTypesWith:(void (^)(NSArray *, NSError *))completionHandler
{
    [ZNetworkManager postDataForBackGround:nil atURL:[ZMappingManager getRequestURLToGetPropertiesTypes] completionHandler:^(NSArray *array, NSError *error)
     {
         NSMutableArray *typesDictionariesArray =[NSMutableArray array];
         NSMutableDictionary* details = [NSMutableDictionary dictionary];
         if (!error)
         {
             NSDictionary *fetchedDictionary = (NSDictionary*) array;
             if([fetchedDictionary isKindOfClass:[NSDictionary class]] == NO)
             {
                 [details setValue:@"Fetched dictionary is null" forKey:@"desription"];
                 completionHandler(nil ,[NSError errorWithDomain:@"MyDomain" code:1 userInfo:details]);
             }
             else
             {
                 if([[[fetchedDictionary objectForKey:@"meta"] objectForKey:@"status"] isEqualToString:@"200"]){
                     NSDictionary *data = [fetchedDictionary objectForKey:@"response"];
                     if([data isKindOfClass:[NSDictionary class]] == NO)
                     {
                         [details setValue:@"Fetched dictionary is null" forKey:@"desription"];
                         completionHandler(nil ,[NSError errorWithDomain:@"MyDomain" code:1 userInfo:details]);
                     }
                     else
                     {
                         NSArray *allTypes = [data objectForKey:@"type"];

                         if([allTypes count] == 0)
                         {
                             [details setValue:@"Fetched dictionary is null" forKey:@"desription"];
                             completionHandler(nil ,[NSError errorWithDomain:@"MyDomain" code:1 userInfo:details]);
                         }
                         else
                         {
                             NSMutableArray *searchTypes = [[NSMutableArray alloc] init];

                             for (NSDictionary *typeDic in allTypes)
                             {
                                 [typesDictionariesArray addObject:typeDic];
                                 ZZameenType *newType = [[ZZameenType alloc] init];
                                 [newType loadFromDictionary:typeDic];
                                 [searchTypes addObject:newType];
                                 NSArray *arrayforChild = [typeDic objectForKey:@"childs"];
                                 for(NSDictionary *typeChild in arrayforChild){
                                     [typesDictionariesArray addObject:typeChild];
                                     ZZameenType *newChild = [[ZZameenType alloc] init];
                                     [newChild loadFromDictionary:typeChild];
                                     [searchTypes addObject:newChild];
                                     newChild = nil;
                                 }
                                 newType = nil;
                             }

                             NSSortDescriptor *typeID_sort = [NSSortDescriptor sortDescriptorWithKey:@"type_id" ascending:YES];
                             [searchTypes sortUsingDescriptors:[NSArray arrayWithObjects:typeID_sort,nil]];
                             [ZGlobals saveSearchTypes:typesDictionariesArray];
                             completionHandler(searchTypes ,nil);
                             searchTypes = nil;
                             details = nil;
                         }
                     }


                 }else{

                 }
             }
         }
     }];

}

不完全确定你有什么问题。如果您只是想将对象插入数组和特定索引,您可以执行以下操作:

[searchTypes insertObject: addObject:newType atIndex:0];

我对上面的方法进行了如下更改:[typesDictionariesArray-insertObject:dict atIndex:[typesDictionariesArray count]-1];该代码以计数分钟1插入对象。。它不是0,如果在添加第一个对象时数组为0,它实际上会崩溃。使用-1它不会崩溃,但在第一节中添加所有住宅和第二个索引,在第二节中添加所有地块也在第二个索引中添加,但在第三节中在第一个索引中添加所有商业