在我的應用程序中,我通過php文件在互聯網和數據顯示在表視圖中的數據庫git dat,但我需要每分鐘重新加載我的數據,我可以每分鐘獲得新的數據,但我不能取代它在表格視圖中。從數據庫重新載入TableView數據
1)你知道該怎麼做嗎?
2)如果你知道如何讓我的代碼更簡單,並刪除那些不需要的代碼?我會感謝你。
我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
關於Q1的確定anwerd – user183790
Q2是否存在 – user183790