0

hii friends i am new in ios Developer.i want to store json array data in particular alphabetical section. Here is my json Response

{
    counts = 0;
    "drycleaning_price" = 10;
    id = 2;
    imagename = "";
    "iron_price" = 16;
    name = Bedsheet;
    "wash_price" = 15;
    "washiron_price" = 14;
},
    {
    counts = 0;
    "drycleaning_price" = 12;
    id = 3;
    imagename = d;
    "iron_price" = 16;
    name = "Coat(Man)";
    "wash_price" = 14;
    "washiron_price" = 13;
},
    {
    counts = 0;
    "drycleaning_price" = 15;
    id = 4;
    imagename = f;
    "iron_price" = 10;
    name = "Jeans(Man)";
    "wash_price" = 12;
    "washiron_price" = 16;
},
    {
    counts = 0;
    "drycleaning_price" = 14;
    id = 3;
    imagename = "";
    "iron_price" = 12;
    name = "Pants(Kid)";
    "wash_price" = 18;
    "washiron_price" = 17;
},
    {
    counts = 0;
    "drycleaning_price" = 15;
    id = 2;
    imagename = s;
    "iron_price" = 10;
    name = "Pants(Man)";
    "wash_price" = 13;
    "washiron_price" = 12;
},
    {
    counts = 0;
    "drycleaning_price" = 12;
    id = 1;
    imagename = "";
    "iron_price" = 32;
    name = "Pillow Cover";
    "wash_price" = 30;
    "washiron_price" = 15;
},
    {
    counts = 0;
    "drycleaning_price" = 10;
    id = 1;
    image = shirt;
    "iron_price" = 15;
    name = "Shirt(Women)";
    "wash_price" = 13;
    "washiron_price" = 12;
},
    {
    counts = 0;
    "drycleaning_price" = 12;
    id = 1;
    imagename = a;
    "iron_price" = 9;
    name = "Shirts(Man)";
    "wash_price" = 10;
    "washiron_price" = 25;
},
    {
    counts = 0;
    "drycleaning_price" = 10;
    id = 3;
    image = sd;
    "iron_price" = 10;
    name = "Shorts(Women)";
    "wash_price" = 18;
    "washiron_price" = 14;
},
    {
    counts = 0;
    "drycleaning_price" = 10;
    id = 2;
    imagename = "";
    "iron_price" = 24;
    name = "Skirt(Kid)";
    "wash_price" = 13;
    "washiron_price" = 14;
},
    {
    counts = 0;
    "drycleaning_price" = 12;
    id = 2;
    image = tops;
    "iron_price" = 10;
    name = "Tops(Women)";
    "wash_price" = 13;
    "washiron_price" = 10;
},
    {
    counts = 0;
    "drycleaning_price" = 12;
    id = 1;
    imagename = "";
    "iron_price" = 16;
    name = "Tshirt(Kid)";
    "wash_price" = 15;
    "washiron_price" = 13;
}

here is my screen shot

enter image description here

when i click the sidebar alphabet character that time cursor is going to particular section.but my json data show in all the section.but i want alphabetically order data.like of section value b than only store badsheet value.not other value.

Here is My code

- (void)viewDidLoad {
[super viewDidLoad];
[NSThread detachNewThreadSelector:@selector(fetchdata) toTarget:self withObject:nil];
NSLog(@"category type=%@",self.category_type);
animalIndexTitles = @[@"A", @"B", @"C", @"D", @"E", @"F", @"G", @"H", @"I", @"J", @"K", @"L", @"M", @"N", @"O", @"P", @"Q", @"R", @"S", @"T", @"U", @"V", @"W", @"X", @"Y", @"Z"];
   arrayCounts = [NSMutableArray array];
sorting = [NSMutableArray array];

}

here my json data load code

-(void)fetchdata

{ NSString *login= [[NSString stringWithFormat:@"http://item.php"]stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

NSLog(@"----%@", login);
NSURL *url = [NSURL URLWithString:[login stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
//-- Get request and response though URL
NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL:url];


[NSURLConnection sendAsynchronousRequest:request
                                   queue:[NSOperationQueue mainQueue]
                       completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
                           dispatch_async(dispatch_get_main_queue(), ^{
                               if (data) {
                                   dic_property= [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];

                                   NSArray *tempArray = dic_property[@"Data"];
                                   for (int i=0; i<tempArray.count; i++) {
                                       NSMutableDictionary *dictValues = [NSMutableDictionary dictionaryWithDictionary:tempArray[i]];
                                       [dictValues setValue:@"0" forKey:@"counts"];

                                       [sorting addObject:dictValues];

                                       NSSortDescriptor *sort = [NSSortDescriptor sortDescriptorWithKey:@"name" ascending:YES];
                                      arrayCounts=[sorting sortedArrayUsingDescriptors:@[sort]];
                                       NSLog(@"test=%@",arrayCounts);
                                   }
                                   NSLog(@"test=%@",arrayCounts);

                                   [self.tableview reloadData];
                               }
                               else {
                                   NSLog(@"network error, %@", [error localizedFailureReason]);
                               }
                           });

                       }];

}

here is tableview method

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 26;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 100;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return arrayCounts.count;

}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    static NSString *simpleTableIdentifier = @"SimpleTableItem";
    customcell *cell = (customcell *)[self.tableview dequeueReusableCellWithIdentifier:simpleTableIdentifier];
    if (cell == nil)
        cell = [[[NSBundle mainBundle] loadNibNamed:@"customcell" owner:self options:nil] objectAtIndex:0];


        cell.lbl_price.text=[NSString stringWithFormat:@"%@",arrayCounts[indexPath.row][@"washiron_price"]];



    cell.txt_value.text = [NSString stringWithFormat:@"%@",arrayCounts[indexPath.row][@"counts"]];

    cell.lbl_title.text=[NSString stringWithFormat:@"%@",arrayCounts[indexPath.row][@"name"]];


    [cell.stepper addTarget:self action:@selector(itemsChange:) forControlEvents:UIControlEventValueChanged];
    return cell;
}

- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString*)title atIndex:(NSInteger)index
{
    return index;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    return [animalIndexTitles objectAtIndex:section];
}
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
    return animalIndexTitles;
}

Please help.i want to store particular section wise store data.thank u for Advance.

Jigar
  • 1,801
  • 1
  • 14
  • 29

0 Answers0