2016-04-05 7 views
0

これはエラーを投げています。この部分をやろうとしているのは初めてのことです。なぜこのコードで画像を円に丸めることができないのですか?

私の誤差がcell.image.frame...である:

- (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

エラーは何ですか?そして、具体的に何が起こっているのですか? – Hamish

答えて

0

私はそれを考え出しました!私はちょうど細胞を参照していた。不適切な方法で

//------------------------------------------------------------------------------------------------------------------------------------------------- 
- (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

この方法でディスパッチ非同期を使用すると、セルを再利用するときに問題が発生する危険性があります。ユーザーが速くスクロールすると、同時に実行される複数のディスパッチが行われ、最初のコールが2番目のコールの後に終了する可能性があります。これはバグにつながります。 – mt81

+0

これは私に別の質問につながりました。 –

関連する問題