SwiftDeveloper
SwiftDeveloper

Reputation: 7368

Objective C TableView Clear Json Parsing

I have working project with manually data but i want to add json parsing in my project. My codes under i think i need help. ( Must be real time parsing when new item add will be auto release if it possible )

My Table View Codes

- (void)scrollToLastTableViewCell {
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:self.uniqueCodes.count - 1
                                                inSection:0];
    [self.tableView scrollToRowAtIndexPath:indexPath
                          atScrollPosition:UITableViewScrollPositionTop
                                  animated:YES];
}



    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        return 15;
    }

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString *cellid=@"CustomCell";
        CustomTableViewCell *cell=(CustomTableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellid];;


        if(cell==nil)
        {
            cell=[[CustomTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellid];

        }
        cell.nameLabel.text=[NSString stringWithFormat:@"This is cell no %d of this table",indexPath.row+1];
        cell.cellButton1.tag=101+indexPath.row;
        cell.cellButton2.tag=201+indexPath.row;
        cell.cellButton3.tag=202+indexPath.row;
        cell.cellButton4.tag=203+indexPath.row;
        cell.cellButton5.tag=204+indexPath.row;
        cell.SwipableUIView.tag=301+indexPath.row;
     [cell setSelectionStyle:UITableViewCellSelectionStyleNone];


        return cell;
    }

CustomTableViewCell.h

@interface CustomTableViewCell : UITableViewCell

@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UIView *SwipableUIView;
@property (weak, nonatomic) IBOutlet UIButton *cellButton1;
@property (weak, nonatomic) IBOutlet UIButton *cellButton2;
@property (weak, nonatomic) IBOutlet UIButton *cellButton3;
@property (weak, nonatomic) IBOutlet UIButton *cellButton4;
@property (weak, nonatomic) IBOutlet UIButton *cellButton5;
@property (weak, nonatomic) IBOutlet UIButton *cellButton6;
@property (weak, nonatomic) IBOutlet UIButton *cellButton7;

@end

MY Json

{

    "Items": [
        {
            "name": "My new name 1"
        },
        {
            "name": "My new name 2"
        },
        {
            "name": "My new name 3"
        }
    ]
}

Thanks for everything.

Upvotes: 0

Views: 68

Answers (1)

Jose
Jose

Reputation: 106

Are you just looking to parse the unique codes out of the JSON, like this:

NSString *jsonString = /* Your JSON String Here */;
NSData *data = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
NSError *serializationError;
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data
                                                     options:NSJSONReadingMutableContainers
                                                       error:&serializationError];
NSMutableArray *uniqueCodes = json[@"Items"];

Upvotes: 1

Related Questions