OGeek|极客世界-中国程序员成长平台

标题: iphone - UITableView 仅在我上下滚动时显示来自 JSON 的数据 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 12:25
标题: iphone - UITableView 仅在我上下滚动时显示来自 JSON 的数据

UITableView 仅在我上下滚动时显示来自 JSON 数组的数据。当我加载表格 View 时,它显示单元格,但它们是空白的,当我上下滚动时,它开始显示数据。

如何在不滚动的情况下显示带有数据的单元格?

- (void)requestFinishedASIHTTPRequest *)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 *)tableViewUITableView *)tableView cellForRowAtIndexPathNSIndexPath *)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;
}   



Best Answer-推荐答案


完成请求并设置数组后,请确保调用 [self.tableView reloadData];

出于性能和动画目的, TableView 不会在源更改时重新加载其数据。

关于iphone - UITableView 仅在我上下滚动时显示来自 JSON 的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9808752/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4