2010-09-16 48 views
1

OK,首先这种程序可以通过这个代码加载从URL plist中,我把这个如何从URL重新加载数据???只能在viewdidload中加载数据?

- (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文件给init的tableview细胞

- (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]; 

} 

,改变从(void)viewDidLoad将得到的URLRequest到

- (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似乎没有从timeFired

我检查控制台得到任何的plist数据结果,我可以看到有一个plist数据每3秒回来一次 (define REFRESH_STATUS_TIME = 3.0;)

当我的程序重装数据传递给单元失败时有什么错误?

+0

OH我在 - (UITableViewCell *)tableView设置断点:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {...}在这里没有停止 – 2010-09-16 10:02:27

回答

1

我没有看到[self.tableView reloadData];的任何行。你必须调用这个来重新加载你的表格视图数据

+0

哦,什么都没有发生〜 – 2010-09-16 14:16:30

+0

它调用你的 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {...}? – vodkhang 2010-09-16 14:24:27

+0

让我尝试一个断点,我现在就回家 – 2010-09-16 14:51:42