Iphone 如何从URL重新加载数据???只能在viewdidload中加载数据?
好的,首先这个程序可以通过这个代码从URL加载plist,我把它放在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]
- (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]代码>