OK , Сначала эта программа может загрузить 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 не получила никаких списков данных из timeFired
Я проверяю результат консоли, вижу, что данные plist возвращаются каждые 3 секунды
(определить REFRESH_STATUS_TIME = 3.0;)
Что не так, когда моя программа перезагружала данные, передаваемые в ячейку ??