2016-04-05 21 views
0

Bu bir hata veriyor. Bu kısmı yapmaya çalışırken ilk defa, bu yüzden benimle birlikte ol.neden görüntümü bu kodla bir daireye kırpmama izin vermiyor?

Benim hata cell.image.frame... olan:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; 
    if (cell == nil) cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"]; 

    PFObject *group = groups[indexPath.row]; 
    //if(group[PF_GROUP_LOGO] != nil){ 
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{ // go to a background thread to load the image and not interfere with the UI 
     UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:group[PF_GROUP_LOGO]]]]; 
     dispatch_async(dispatch_get_main_queue(), ^{ // synchronize back to the main thread to update the UI with your loaded image 
      cell.layer.cornerRadius = cell.image.frame.size.width/2; 
      cell.layer.masksToBounds = YES; 
      cell.imageView.image = image; 
      cell.textLabel.text = group[PF_GROUP_NAME]; 
      cell.detailTextLabel.text = [NSString stringWithFormat:@"%d users", (int) [group[PF_GROUP_MEMBERS] count]]; 
      cell.detailTextLabel.textColor = [UIColor lightGrayColor]; 

     }); 
    }); 
    return cell; 
} 
+1

Hata nedir? Ve özellikle hangi hat üzerinde oluyor? – Hamish

cevap

0

Ben bunu anladım! Sadece hücre referansı yapıyordum. uygunsuz bir şekilde.

//------------------------------------------------------------------------------------------------------------------------------------------------- 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
//------------------------------------------------------------------------------------------------------------------------------------------------- 
{ 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; 
    if (cell == nil) cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"]; 

    PFObject *group = groups[indexPath.row]; 
    //if(group[PF_GROUP_LOGO] != nil){ 
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{ // go to a background thread to load the image and not interfere with the UI 
     UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:group[PF_GROUP_LOGO]]]]; 
     dispatch_async(dispatch_get_main_queue(), ^{ // synchronize back to the main thread to update the UI with your loaded image 

      cell.imageView.image = image; 
      cell.imageView.layer.cornerRadius = cell.imageView.frame.size.height /2; 
      cell.imageView.layer.masksToBounds = YES; 
      cell.imageView.layer.borderWidth = 0; 
      cell.textLabel.text = group[PF_GROUP_NAME]; 
      cell.detailTextLabel.text = [NSString stringWithFormat:@"%d users", (int) [group[PF_GROUP_MEMBERS] count]]; 
      cell.detailTextLabel.textColor = [UIColor lightGrayColor]; 

     }); 
    }); 
    return cell; 

} 
+0

Sevk dağıtımını bu şekilde kullanmak, hücre yeniden kullanıldığında sorun yaşamazsınız. Kullanıcı hızlı bir şekilde kaydırırsa, aynı anda çalışan çoklu gönderiminiz olacak ve ilk aramanın saniyeden sonra bitmesi olasıdır. Bu bir hataya yol açacaktır. – mt81

+0

Bu bana başka bir soruya yol açtı, bir başka iş parçacığında gerçek hızlı yayınladım. –

İlgili konular