Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何从URL重新加载数据???只能在viewdidload中加载数据?_Iphone_Url_Sdk_Cell_Reloaddata - Fatal编程技术网

Iphone 如何从URL重新加载数据???只能在viewdidload中加载数据?

Iphone 如何从URL重新加载数据???只能在viewdidload中加载数据?,iphone,url,sdk,cell,reloaddata,Iphone,Url,Sdk,Cell,Reloaddata,好的,首先这个程序可以通过这个代码从URL加载plist,我把它放在 - (void)viewdidLoad{ NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://someurl.php"] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0]

好的,首先这个程序可以通过这个代码从URL加载plist,我把它放在

- (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文件初始化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];

}
并将get-URLrequest从
(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单元格初始化似乎没有从
timeired

我检查控制台结果,我可以看到每3秒返回一次plist数据 (定义刷新状态时间=3.0;)


当我的程序重新加载数据传递到单元格失败时,会出现什么问题???

我没有看到任何带有
[self.tableView reloadData]的行。您必须调用此函数才能重新加载表视图数据

我没有看到任何带有
[self.tableView reloadData]的行。必须调用此函数才能重新加载表视图数据

哦,我在-(UITableViewCell*)tableView:(UITableView*)tableView CellForRowatineXpath:(NSIndexPath*)indexPath{…}处设置了断点哦,我在-(UITableViewCell*)tableView:(UITableView*)tableView CellForRowatineXpath:(NSIndexPath*)indexPath{…}处设置了断点没有停止调用-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{…}?否。。。我认为它没有调用这个函数,因为它在断点下的下一行没有停止,这个函数也不是调用“-(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section{return[self.plist count];}“如果您或国家/地区很晚,我们明天可以试着解决这个问题……很抱歉,您确定它会调用您的
[self.tableView reloadData]它是否调用您的-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{…}?否。。。我认为它没有调用这个函数,因为它在断点下的下一行没有停止,这个函数也不是调用“-(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section{return[self.plist count];}“如果您或国家/地区很晚,我们明天可以试着解决这个问题……很抱歉,您确定它会调用您的
[self.tableView reloadData]