当我上下滚动时,UITableView 仅显示 JSON 数组中的数据。当我加载表格 View 时,它显示单元格,但它们是空白的,当我上下滚动时,它开始显示数据。
如何在不滚动的情况下显示包含数据的单元格?
- (void)requestFinished:(ASIHTTPRequest *)request
{
if (request.responseStatusCode == 400) {
NSLog( @"Code already used");
} else if (request.responseStatusCode == 403) {
NSLog( @"Code already used");
} else if (request.responseStatusCode == 200) {
NSLog(@"%@",[request responseString]);
NSString *response = [request responseString];
const char *convert = [response UTF8String];
NSString *responseString = [NSString stringWithUTF8String:convert];
responseArray = [responseString JSONValue];
Nrows = [responseArray count];
}
}
- (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] autorelease];
}
NSDictionary *dict = [responseArray objectAtIndex:indexPath.row];
cell.detailTextLabel.text = [dict objectForKey:@"allfeeds"];
cell.textLabel.adjustsFontSizeToFitWidth = YES;
cell.textLabel.font = [UIFont systemFontOfSize:12];
cell.textLabel.minimumFontSize = 10;
cell.textLabel.numberOfLines = 4;
cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
cell.textLabel.text = [dict objectForKey:@"allfeeds2"];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
最佳答案
完成请求并设置数组后,请务必调用 [self.tableView reloadData];
出于性能和动画目的,表格 View 在源更改时不会重新加载数据。
关于iphone - 当我上下滚动时,UITableView 仅显示来自 JSON 的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9808752/