iphone - 当我上下滚动时,UITableView 仅显示来自 JSON 的数据

标签 iphone ios uitableview

当我上下滚动时,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/

相关文章:

ios - NSObject 类工作

ios - 我们如何在单例中使用 Alamofire NetworkReachabilityManager?

iphone - 在 iOS 中谷歌查询经度和纬度时没有得到 json 响应?

ios - 在 Xcode 7 中禁用 Bitcode 时无法将文件上传到应用程序商店

ios - 在我的 UITableView 中设置特定单元格的高度

iOS - 有没有办法选择一个单元格但不滚动到它?

ios - 检测 Textview 滚动和 Tableview 滚动

iphone - 更改枚举类型值

ios - 如何编辑 WKWebView 显示的键盘附件 View ?

ios - 将庞大的 Firebase 数据库作为事务更新