それぞれ50Kb〜2 Mbの画像を20〜25ダウンロードして、テーブルビューに表示する必要があります。これにASIHTTPRequestasynリクエストを使用しました。しばらくすると、アプリが動かなくなってしまうのを観察しました。非同期呼び出しを使用しているため、これは発生しないはずです。ASIHTTPRequestに問題があると思い、didFinishedセレクターがメインスレッドで呼び出されることを確認しました。私がしているのは
-(void)didFinishedDownloadingImage:(ASIHTTPRequest *)request
{{
NSData * responseData = [request responseData];
UIImage * image = [UIImage imageWithData:responseData];
[[data objectAtIndex:request.tag] setImage:image];
[self.tableView reloadData];
}
これで問題はないと思います。また、cellforrowatindexpathで私はただします
-(UItableViewCell *)tableviewView:(UItableView *)tableview
cellForItemAtIndexPath:(NSIndexPath *)indexPath {
UserProfile * user = [data objecAtIndex:indexpath.row];
UITableViewCell * cell = [tableView
dequeueReusableCellWithReuseIdentifier:@ "ProfileCell"
forIndexPath:indexPath];
if(cell == nil){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewDefaultStyle];
}
NSString * fullname = [NSString stringWithFormat:@ "%@ \ n%@"、
user.firstname、user.lastname];
if(user.image!= nil)
[cell.imageView setImage:user.image];
そうしないと{
[cell.imageView setImage:[UIImage imageNamed:@ "placeholder.jpg"]];
}
[cell.label setText:fullname];
セルを返します。
}
ただし、アプリは低速で1〜2秒間フリーズしますが、これはかなりの時間です。これを非常にスムーズに行うアプリを見てきました。上記のコードを使用するとパフォーマンスが大幅に向上する固定サイズの5Kbの画像を使用してみました。すべてのダウンロードはASIHTTPを介して他のスレッドで行われるため、この場合、なぜそれが大きな画像に違いをもたらすのかわかりません。