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

时间:2015-04-22 05:04:31

标签: ios objective-c

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

这是URL link

在Homes Plots and Commercial的三个部分中,我想在每个部分添加所有房屋所有地块和所有商业,并在每个部分中添加他们的结果,在每个部分的顶部All Homes,All Plots和All Commercial

   - (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{

                 }
             }
         }
     }];

}

1 个答案:

答案 0 :(得分:0)

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

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