ОК,Сначала эта программа может загрузить plist из URL-адреса по этому коду,и я поместил его в
- (void)viewdidLoad{
NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://someurl.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];
}
чем я беру файл plist для инициализации ячейки таблицы
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"cell";
LightCell0 *cell =(LightCell0 *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[LightCell0 alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
// Set up the cell…
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
cell.lightLocation.text = [[[self.plist objectAtIndex:indexPath.row] valueForKey: @"nodeName"]description];
return cell;
}
теперь мне нужно продолжать перезагружать данные URL, чтобы инициализировать его
Поэтому я добавляю
-(void)viewDidLoad{
timer = [NSTimer scheduledTimerWithTimeInterval:REFRESH_STATUS_TIME
target:self
selector:@selector(timerFired:)
userInfo:nil
repeats:YES];
}
и измените URL-запрос на получение с (void)viewDidLoad
на
- (void)timerFired:(NSTimer *)theTimer{
NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.someurl.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];
NSLog(@"Timefired!!!!");
}
ВОТ ПРОБЛЕМА ~
Ячейка TableView init, похоже, не получила никаких данных plist из timeFired
Я проверяю результат консоли, я вижу, что данные plist возвращаются каждые 3 секунды (определить REFRESH_STATUS_TIME = 3.0;)
Что не так, когда моя программа перезагружает передачу данных в ячейку со сбоем??