我有一个TableView的界面,是一个列表页,只有一个Section,每一个Cell里都有一张图片是从服务器异步加载的。
我用ASIHttpRequest去加载图片,在每个Request里已经通过UserInfo带上了这个Cell的NSIndexPath.row,然后回调的时候,就按照这个NSIndexPath去更新Cell的默认占位图片。
但是,我发现刷两下以后,Cell里的图片又乱掉了。
貌似我NSIndexPath.row没用一样的,有没有人也遇到过一样的问题啊。
完整代码太复杂,把涉及到网络的代码贴一下
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{// ... [self loadImageWithURL:[self.dataSource objectAtIndex:indexPath.row] index:indexPath.row]; // 这是我自己定义的一个方法// ...} - (void)loadImageWithURL:(NSString *)aURL index:(NSInteger)anIndex { ASIHTTPRequest *asiRequest = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:aURL]]; asiRequest.delegate = self; asiRequest.userInfo = [NSDictionary dictionaryWithObjectsAndKeys: [NSString stringWithFormat:@"%d", anIndex], @"index", nil]; asiRequest.requestMethod = @"GET"; [asiRequest startAsynchronous]; } - (void)requestFinished:(ASIHTTPRequest*)request { NSInteger index = [[request.userInfo objectForKey:@"index"] intValue]; UITableViewCell *cell = [tableView cellForRowAtIndexPath: [NSIndexPath indexPathForRow:index inSection:0]]; cell.imageView.image = [UIImage imageWithData:request.responseData];}
精慕HU
慕桂英3389331
相关分类