In my app i git dat from DB by php file in internet and data shown in a Table view but i need to reload my data every minute, i can get the new data every minute but i cant replace it in the table view.
1) Do you know how to do it?
2) If you know how to get my code more simple, and delete that unNeeded codes? I’ll be thanks to you.
My ViewController.m
#import "ViewController.h"
#import "CJSONDeserializer.h"
@implementation ViewController
@synthesize tblMain, rows;
NSURL *url;
NSString *jsonreturn;
NSData *jsonData;
NSError *error;
NSDictionary *dict;
UITableViewCell *cell;
static NSString *CellIdentifier;
- (void)viewDidLoad{
[super viewDidLoad];
[self GetData];
}
-(void)GetData{
url = [NSURL URLWithString:@"http://ar2.co/savola/"];
jsonreturn = [[NSString alloc] initWithContentsOfURL:url];
NSLog(jsonreturn);
jsonData = [jsonreturn dataUsingEncoding:NSUTF32BigEndianStringEncoding];
dict = [[[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:&error] retain];
rows = [dict objectForKey:@"savola"];
NSLog(@"Array: %@",rows);
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [rows count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
dict = [rows objectAtIndex: indexPath.row];
cell.textLabel.text = [NSString stringWithFormat:@"%@ - %@", [dict objectForKey:@"company"], [dict objectForKey:@"price"]];
cell.detailTextLabel.text = [dict objectForKey:@"time"];
return cell;
}
@end
To force a table to reload its information, call
[self.tableView reloadData]from your view controller class. That will call all of the data source methods again, and it will update the display as well.