使用SDWebImage
将gif加载到我的UITableViewCell
中。它实际上非常快,但tableview
似乎不会加载,直到用户实际滚动tableview
。使用UITableViewCell加载问题
有关如何解决此问题的任何建议?
这是我UITableView
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return self.gifArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *MyIdentifier = @"Cell";
RDGifGridTableViewCell *cell = (RDGifGridTableViewCell *)[tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"RDGifGridTableViewCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
cell.urlLabel.text = [self.gifArray objectAtIndex:indexPath.row];
cell.urlLabel.textColor = [UIColor clearColor];
[cell.imageView sd_setImageWithURL:[NSURL URLWithString:cell.urlLabel.text] placeholderImage:nil options:SDWebImageCacheMemoryOnly];
return cell;
}
这是我如何添加内容到发生在viewDidLoad中数组:
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString]];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
NSArray *idArray = [json objectForKey:@"data"];
for (NSDictionary *ids in idArray) {
NSDictionary *images = ids[@"images"];
NSDictionary *fixedHeightImage = images[@"fixed_width"];
self.gifURL = fixedHeightImage[@"url"];
[self.gifArray addObject:self.gifURL];
[self.tableView reloadData];
}
你可以发布“sd_setImageWithURL:”方法的代码。我认为它有问题... – Yogendra