Hi ,everyone I got problem here
I need to update a plist data in a period time
and I use Tab Bar to switch 2 views
When I select to view1 ,It will load data from an URL
But if I switch to view2 , the view1 still update the data
If you switch to view2 and switch back ,view2 keep updating the data.
and this is the code I'm using to update the data in LoadData.h
@interface LoadData : UITableViewController < NSNetServiceBrowserDelegate > {
NSArray *plist;
NSTimer *timer;
}
in LoadData.m
static const float REFRESH_STATUS_TIME = 2.0;
- (void)viewDidLoad {
timer = [NSTimer scheduledTimerWithTimeInterval:REFRESH_STATUS_TIME
target:self
selector:@selector(timerFired:)
userInfo:nil
repeats:YES];
[super viewDidLoad];
}
- (void)timerFired:(NSTimer *)theTimer{
NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://10.85.28.99/envotouch/req_light.php"]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
NSLog(@"\n\nCONNECTION: %@", theConnection);
NSData *returnData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:nil error:nil];
NSString *listFile = [[NSString alloc] initWithData:returnData encoding:NSASCIIStringEncoding];
self.plist = [listFile propertyList];
[self.tableView reloadData]
}
So my question is how to terminated the data update when I switch to another view ?
thanks for the reply.....this a big bug annoying me