我正在使用 hpple 从网页获取数据并将其显示在表格视图中,但如果没有数据或无法获取数据,我希望单元格显示“无数据”。但正因为如此,当加载数据时,它会在视图控制器上显示无数据大约一秒钟,这是我正在使用的代码:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
switch (section) {
case 0:
if ((_deli.count > 0)) {
return _deli.count;
}
else {
return 1;
}
break;
case 1:
if ((_entrees.count > 0)) {
return _entrees.count;
}
else {
return 1;
}
break;
}
return 0
}
接着
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
//[UIColor colorWithRed:191.0f/255.0f green:48/255.0f blue:48/255.0f alpha:1.0]
cell.textLabel.textColor = [UIColor whiteColor];
cell.textLabel.font = [UIFont fontWithName:@"TimesNewRomanPS-BoldMT" size:17.0f];
if (indexPath.section == 0) {
if ([tableView numberOfRowsInSection:0] == _deli.count ) {
Items *thisDeli = [_deli objectAtIndex:indexPath.row];
cell.textLabel.text = thisDeli.title;
}
else { cell.textLabel.text = @"No Data Avaiable";
}
}
else if (indexPath.section == 1) {
if ([tableView numberOfRowsInSection:1] == _entrees.count) {
Items *thisEntree = [_entrees objectAtIndex:indexPath.row];
cell.textLabel.text = thisEntree.title;
}
else { cell.textLabel.text = @"No Data Avaiable";
}
}
}
有没有办法延迟“无数据”短语的出现或仅在它为空白或无法获取时显示它。
这是我的 NSURLConnection
- (void) loadDataUsingNSURLConnection {
NSString *url = @"http://ueat.site88.net/westTest.xml";
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]];
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
NSLog(@"response == %@", response);
}
提前感谢您的帮助。
干杯