Iphone 当我上下滚动时,UITableView仅显示JSON中的数据
当我上下滚动时,UITableView仅显示JSON数组中的数据。当我加载表格视图时,它会显示单元格,但它们是空白的,当我上下滚动时,它会开始显示数据 如何在不滚动的情况下显示包含数据的单元格Iphone 当我上下滚动时,UITableView仅显示JSON中的数据,iphone,ios,uitableview,Iphone,Ios,Uitableview,当我上下滚动时,UITableView仅显示JSON数组中的数据。当我加载表格视图时,它会显示单元格,但它们是空白的,当我上下滚动时,它会开始显示数据 如何在不滚动的情况下显示包含数据的单元格 - (void)requestFinished:(ASIHTTPRequest *)request { if (request.responseStatusCode == 400) { NSLog( @"Code already used"); } else if
- (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;
}
我有一个类似的问题,不久前在苹果的开发者论坛上得到了我的答案,这解决了我的问题: 从您所描述的内容来看,我猜问题更可能出现在cellForRowAtIndexPath或任何您实际配置单元格的地方,而不是您发布的代码中。当dequeueReusableCellWithIdentifier返回一个现有单元格,但您没有完全重置其现有状态时,可能会出现类似您的问题
完整的问题和答案可在此处找到(需要登录):这些问题通常是由UITableView缓存引起的,该缓存使用相同的单元标识符(在您的示例中为-@“单元”)将其可用的缓存UITableViewCell排出队列 尝试为表中的每个单元格创建一个单元格标识符。您可以通过以下方式使用NSIndexPath参数创建此差异:
NSString* cellIdentifier = [NSString stringWithFormat:@"Cell%d",indexPath.row];
当然,假设您在加载数据后没有更改单元格的内容。当您完成请求并设置数组时,请确保调用
[self.tableView reloadData]代码>
出于性能和动画目的,当源更改时,表视图不会重新加载其数据。而不是异步启动请求(非阻塞)
尝试同步执行(阻塞)
你能告诉我如何重置它的状态吗?你必须改变手机上的每一点信息。假设您有一个标题、一个副标题和一个accessoryType.UITableViewCellAccessoryCheckmark
,因此对于您绘制的每个单元格,您必须修改这三个,即使其中一个对于所有单元格都是相同的,您只需重写它。但在我的例子中,我从json获得了NSArray,每个单元格中都有两个文本字段,类似于文本标签和详细信息文本。NSString*CellIdentifier=[NSString stringWithFormat:@“Cell%d”,indexath.row];UITableViewCell*单元格=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];如果(cell==nil){cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]autorelease];}我这样做了,但运气不好,当我加载表视图时,它显示为空,当滚动时,它开始显示值,如果我再次上升,它开始显示其余的值,我正在异步加载它。当我向下滚动它的状态显示值时,请重新编译一些内容,但它加载为空。它神奇地完成了!:)非常感谢它的工作。。现在[请求同步启动];已经解决了
[request startAsynchronously];
[request startSynchronously];