how to parse data in tableview from server??

I m trying to fetch data from server and want to display it on the table view. My cell is custom cell.. Custom tableviewCell has labels and buttons. Now, i have 3 classes .


1..invoiceCell(sub class of tableviewCell) - In this class i have outlets of lables.

@property (weak, nonatomic) IBOutlet UILabel *lblID;

@property (weak, nonatomic) IBOutlet UILabel *lbldate;

@property (weak, nonatomic) IBOutlet UILabel *lblduedate;

@property (weak, nonatomic) IBOutlet UILabel *lblamount;

@property (weak, nonatomic) IBOutlet UILabel *lblstatus;

2.invoiceObject.h(sub class of nsobject) - in this class I have @properties...

@property (nonatomic) int *ID;

@property (nonatomic,strong) NSString *date;

@property (nonatomic,strong) NSString *total;

@property (nonatomic,strong) NSString *duedate;

@property (nonatomic,strong) NSString *status;

-(instancetype)initWithid :(int)ID andDate :(NSString *)idate andTotal :(NSString *)itotal andDuedate :(NSString *)iduedate andStatus :(NSString *)istatus;


invoiceObject.m

-(instancetype)initWithid :(int)ID andDate :(NSString *)idate andTotal :(NSString *)itotal andDuedate :(NSString *)iduedate andStatus :(NSString *)istatus

{

self = [super init];

if(self)

{

self.ID = ID;

self.date = idate;

self.total = itotal;

self.duedate = iduedate;

self.status = istatus;

}

return self;

}


3.invoiceTV(sub class of tableViewController) ... identifier name "Cell".

- (void)viewDidLoad {

[super viewDidLoad];


NSURL *url = [NSURL URLWithString:@"http:/

NSData *jsondata = [NSData dataWithContentsOfURL:url];

NSDictionary *dataDictionary = [NSJSONSerialization

JSONObjectWithData:jsondata options:0 error:nil];


for (NSDictionary *bpDictionary in dataDictionary)

{

innvoiceObject *currenInvoice = [[innvoiceObject alloc] initWithid:[bpDictionary objectForKey:@"id"] andDate:[bpDictionary objectForKey:@"invoicedate"] andTotal:[bpDictionary objectForKey:@"total"] andDuedate:[bpDictionary objectForKey:@"duedate"] andStatus:[bpDictionary objectForKey:@"status"]];

[self.objectHolderArray addObject:currenInvoice];

}

}

- (void)didReceiveMemoryWarning {

[super didReceiveMemoryWarning];

}

-(NSMutableArray *)objectHolderArray

{

if(!_objectHolderArray) _objectHolderArray = [[NSMutableArray alloc]init];

return _objectHolderArray;

}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

return 1;

}

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

return [self.objectHolderArray count];

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:

(NSIndexPath *)indexPath

{

NSString *CellIdentifier = @"Cell";

invoiceCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier

];

innvoiceObject *currentInvoice = [self.objectHolderArray

objectAtIndex:indexPath.row];

cell.lblID.text = [NSString stringWithFormat:@"%d",currentInvoice.ID];

cell.lbldate.text = currentInvoice.date;

cell.lbldate.text = currentInvoice.duedate;

cell.lblamount.text = currentInvoice.total;

cell.lblstatus.text = currentInvoice.status;


return cell;

}


I had tried this way But m not getting any response in table view its shows me empty table view in simulator. When i m trying to debug it shows tableView with no data in it. And console is also blank when i debug..I m trying this since 3,4 days.. please help!!



thank U in advance....

Json data format is as below:


{

"success": "1",

"response": [

{

"id": "1181",

"invoicedate": "2016-07-04",

"duedate": "2016-07-04",

"total": "1500.00",

"status": "Unpaid"

},

{

"id": "1091",

"invoicedate": "2015-11-15",

"duedate": "2015-11-29",

"total": "6249.00",

"status": "Paid"

},

First of all, I would recommend that you separate the concerns into the following objects:


- Object Model > where you store your data

- Facade object > where you will make the request, parse the JSON data and store the objects in the model

- Table View Datasource where you implement the UITableViewDataSource protocol (simple object that inherits from NSObject)

- Table View Delegate: where you implement the UITableViewDelegate protocol (simple object that inherits from NSObject)


Instead of having:


tableView.dataSource = self;
tableView.delegate = self;


You will have:


tableView.dataSource = <instance of your Table View Datasource object>;
tableView.delegate = <instance of your Table View Delegate object>;

1. You should NOT not use dataWithContentsOfURL. It is synchronous and therefore blocks the main thread (i.e screen updates and touches).


Important

Do not use this synchronous method to request network-based URLs. For network-based URLs, this method can block the current thread for tens of seconds on a slow network, resulting in a poor user experience, and in iOS, may cause your app to be terminated.

Instead, for non-file URLs, consider using the

dataTaskWithURL:completionHandler:
method of the
NSURLSession
class. See URL Session Programming Guide for details.


2. You can directly get an array from a dictionary by using the allValues property of NSDictionary, no need to loop. If you want to convert objects to your invoiceObject.m type, it's better to create a factory method in invoiceObject.m (better call the class Invoice than invoiceObject).


3. You should handle any error that occurs in the call to JSONObjectWithData:options:error:

how to parse data in tableview from server??
 
 
Q